gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 22:04:44 24 4
gpt4 key购买 nike

我有一个简单的 FrameLayout,它支持 CardView 作为第一项,TextView 作为第二项,所以 TextView 必须位于膨胀 View 的顶部。这适用于前 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>

最佳答案

如果有人来到这里并且设置海拔的解决方案对他们不起作用(比如在我的情况下,我需要在 CardView 上方绘制图像并在其上有阴影是 Not Acceptable ),您可以通过将 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>

关于android - CardView 位于 FrameLayout 之上,但首先声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31629409/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com