【发布时间】: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