gpt4 book ai didi

android - CardView自定义背景

转载 作者:行者123 更新时间:2023-11-30 00:38:01 25 4
gpt4 key购买 nike

我尝试在我的 CardView 中添加自定义背景。这是我的来源

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/item_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff00"
android:orientation="vertical">


<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="12dp"
card_view:cardElevation="12dp"
card_view:cardPreventCornerOverlap="false"
card_view:contentPadding="0dp"
android:layout_margin="16dp"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#cccccc">
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>

And this is a result

正如您在 Cardview 中看到的那样,我有 LinearLayout 和 RelativieLayout。RelativeLayout 的背景颜色是#cccccc,但 cornerradius 和 elevetion 不适用于自定义背景颜色。(请看我的图片)我该如何解决我的问题?

最佳答案

CardView 内的线性布局重叠您的cardview 的顶角,因为线性布局的固定高度.给cardview赋予高度,做线性布局时match_parent,给cardview赋予contentPadding,使角可见。

这是代码和截图。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/item_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff00"
android:orientation="vertical">


<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="80dp"
card_view:cardCornerRadius="12dp"
card_view:cardElevation="12dp"
card_view:cardPreventCornerOverlap="true"
card_view:contentPadding="2dp"
android:layout_margin="16dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#cccccc">
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>

截图

Image

关于android - CardView自定义背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43089835/

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