Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android CardView位于FrameLayout之上,但首先声明_Android_Xml_Android 5.0 Lollipop_Android Support Library_Android Cardview - Fatal编程技术网

Android CardView位于FrameLayout之上,但首先声明

Android CardView位于FrameLayout之上,但首先声明,android,xml,android-5.0-lollipop,android-support-library,android-cardview,Android,Xml,Android 5.0 Lollipop,Android Support Library,Android Cardview,我有一个简单的框架布局,第一项是支持CardView,第二项是TextView,所以TextView必须位于扩展视图的顶部。这适用于Lolipop之前的游戏,但21+卡在布局中占据了最重要的位置,为什么会这样,如何解决这个问题?相对论也一样。 布局: 只需在卡片视图中添加文本视图,据我所知,框架布局中的z顺序未定义,但最后一个布局视图应最后绘制 这可能与棒棒糖中的卡片视图使用标高有关,而它们返回到边界绘制代码pre lollipop上。以防有人来到这里,而设置标高的解决方案对他们不起作用(就像

我有一个简单的框架布局,第一项是支持CardView,第二项是TextView,所以TextView必须位于扩展视图的顶部。这适用于Lolipop之前的游戏,但21+卡在布局中占据了最重要的位置,为什么会这样,如何解决这个问题?相对论也一样。 布局:



只需在卡片视图中添加文本视图,据我所知,框架布局中的z顺序未定义,但最后一个布局视图应最后绘制


这可能与棒棒糖中的卡片视图使用标高有关,而它们返回到边界绘制代码pre lollipop上。

以防有人来到这里,而设置标高的解决方案对他们不起作用(就像在我的例子中,我需要在
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>

这对我有用!
我参加讨论可能有点晚了,但如果您有能力放弃
CardView
的提升,您可以将XML布局中
CardView
cardElevation
属性设置为
0dp

像这样:

app:cardElevation="0dp"

只需将文本视图添加到卡片视图中,就我所知,地图的z顺序在框架布局中未定义,但最后一个布局视图应最后绘制。这可能与棒棒糖中的卡片视图使用立面有关,而它们返回到边框绘制代码pre lollipop上。事实上,我只需要卡片用于背景和带有sh的漂亮角落另外,卡的顶部还有RecyclerView和其他卡,它们的角必须与主卡重叠。我找到了在21+中修复它的方法。是的,你是对的,为TextView设置高程可以解决21+上的问题。还有什么问题吗?似乎你已经将它与pre lollipop和lollipop一起使用了?:)我让我的cardview设置了4dp高程。我和matchparent的框架布局在cardview下面。将framelayout的标高设置为5dp,并完成其设置。到目前为止没有问题。哦,天哪,你在几个小时的搜索后救了我!干杯,伙计!
<?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">

    <!-- Add this layout as parent of CardView -->
    <LinearLayout
        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" />

    </LinearLayout>
    <!--Close parent layout-->

    <TextView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:background="#0000ff"
        android:gravity="center"
        android:text="i am top view!"
        android:textAllCaps="true"
        android:textColor="#00ff00"
        android:textSize="30sp" />

</FrameLayout>
app:cardElevation="0dp"