【发布时间】:2015-07-25 17:50:48
【问题描述】:
我有一个简单的 FrameLayout,它支持 CardView 作为第一项,TextView 作为第二项,所以 TextView 必须位于膨胀视图的顶部。这适用于 Lolipop 之前的版本,但在 21+ 卡上占据布局的首位,为什么会这样以及如何解决这个问题?与相对布局相同。 布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="20dp"
app:cardBackgroundColor="#ff0000"
app:cardUseCompatPadding="false"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="i am top view!"
android:gravity="center"
android:layout_gravity="center"
android:textSize="30sp"
android:textAllCaps="true"
android:textColor="#00ff00"
android:background="#0000ff"
/>
</FrameLayout>
【问题讨论】:
-
只需将您的文本视图添加到卡片视图中,据我所知,映射在框架布局中未定义 z 顺序,但最后布局的视图应最后绘制。这可能与棒棒糖中的卡片视图使用高程有关,而它们又依赖于棒棒糖之前的边框绘制代码。
-
事实上,我只需要背景卡和带有阴影的漂亮角落。卡片顶部还有 RecyclerView 与其他卡片,它们的角必须与主卡片重叠。我找到了在 21 岁以上修复它的方法。
标签: android xml android-5.0-lollipop android-support-library android-cardview