我有一个简单的FrameLayout,支持CardView作为第一项,TextView作为第二项,所以TextView必须位于膨胀视图的顶部。这工作在前棒棒糖,但在21+卡在布局中占据最重要的位置,为什么是这样,以及如何解决这个问题?RelativeLayout也是如此。布局:
<?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>
发布于 2015-07-25 10:00:50
只需在卡片视图中添加文本视图,据我所知,z顺序在框架布局中是未定义的,但最后的布局视图应该是最后绘制的。
这可能与棒棒糖中的卡视图有关,而在使用标高时,则返回到边框绘制代码前的棒棒糖。
发布于 2016-04-05 05:16:24
如果有人来到这里,而设置高程的解决方案对他们不起作用(就像我的例子一样,我需要在CardView
之上绘制一个图像,并且在上面有一个阴影是不可接受的),您可以通过将CardView
封装到另一个FrameLayout
中来解决这个问题。在提供的示例中,它应该如下所示:
<?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">
<!-- This is the added FrameLayout -->
<FrameLayout
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"
/>
</FrameLayout>
<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>
发布于 2018-05-24 07:18:04
我可能会晚一点加入讨论,但是如果您能够放弃CardView
的提升,您可以将CardView
的CardView
属性设置为0dp
。
就像这样:
app:cardElevation="0dp"
https://stackoverflow.com/questions/31629409
复制相似问题