2014-10-28 29 views
0

我想实现一个滑动式卡牌效果,就像应用火种: https://play.google.com/store/apps/details?id=com.tinder&hl=en_GB的ViewGroup夹儿童不能设置为false

当我刷我的卡,该子视图总是由它的容器,即使修剪我将clipchildren和cliptopadding设置为false。任何想法为什么?

的CardStack是我的自定义容器布局延伸的RelativeLayout XML:,孩子视图的BUTTOM被裁剪

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<com.wenchao.cardstack.CardStack 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:padding="20dp" 
    android:clipChildren="false" <!--- false --> 
    android:clipToPadding="false" 
    android:layout_weight="3" 
    /> 


<RelativeLayout 

    android:layout_weight="1" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:orientation="horizontal" 
    android:background="#FF00FF" 
    > 
    <Button 
     android:layout_centerHorizontal="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="B" 
     android:id="@+id/info" 
     /> 
    <Button 
     android:id="@+id/like" 
     android:layout_toLeftOf="@+id/info" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="A" 
     /> 
    <Button 
     android:id="@+id/dislike" 
     android:layout_toRightOf="@+id/info" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="C" 
     /> 

</RelativeLayout> 

前刷卡

enter image description here

刷卡后:(

enter image description here

----------------编辑-----------------------

我发现问题在线性布局中,最后一个孩子始终显示在顶部(较大的Z-index)。因此,即使叠叠式容器不夹住儿童,其子女仍然会显示在下面的下方视图下方。所以最好切换到相对布局。

但我不是很想,因为RelativeLayout没有很好的“layout_weight”功能来指定高度百分比。所以情况是,我想要一种方法来轻松控制z-index(对于线性布局来说不可能的),并且还想保持“layout_weight”特性(似乎只对linearlayout可行)。任何想法??

回答

0

为什么你需要layout_weight?我假设顶视图填满所有可用空间?现在,您将屏幕分为四个区域,但如果您可以在任意一个视图上设置大小,问题就会解决。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 


    <RelativeLayout 
     android:id="@+id/button_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="@dimen/large_bottom_padding" 
     android:background="#FF00FF" 
     > 
     <Button 
      android:layout_centerHorizontal="true" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="B" 
      android:id="@+id/info" 
      /> 
     <Button 
      android:id="@+id/like" 
      android:layout_toLeftOf="@+id/info" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="A" 
      /> 
     <Button 
      android:id="@+id/dislike" 
      android:layout_toRightOf="@+id/info" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="C" 
      /> 

    </RelativeLayout> 

    <com.wenchao.cardstack.CardStack 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"   <!-- Not really important --> 
     android:layout_alignParentTop="true"   <!-- Because of these lines --> 
     android:layout_above="@id/button_container" <!-- Because of these lines --> 
     android:padding="20dp" 
     android:clipChildren="false" <!--- false --> 
     android:clipToPadding="false" 
     /> 

</RelativeLayout