【问题标题】:ViewGroup clip children can not be set falseViewGroup 剪辑子项不能设置为 false
【发布时间】:2014-10-28 11:20:26
【问题描述】:

我正在尝试实现一种可滑动的卡片效果,就像应用程序 Tinder 一样: https://play.google.com/store/apps/details?id=com.tinder&hl=en_GB

当我刷卡时,即使我将clipchildren 和cliptopadding 设置为false,子视图也总是被其容器裁剪。知道为什么吗????

CardStack 是我的自定义容器布局扩展了 RelativeLayout xml:

<?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>

刷卡前

滑动后,子视图的底部被剪掉:(

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

我发现问题是在线性布局中,最后一个孩子总是显示在顶部(更大的 z-index)。因此,即使 cardstack 容器不剪切孩子,它的孩子仍然显示在下面的下一个视图下方。所以最好切换到相对布局。

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

【问题讨论】:

    标签: android android-layout viewgroup clip


    【解决方案1】:

    为什么需要 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-16
      • 2012-06-09
      • 1970-01-01
      相关资源
      最近更新 更多