带有圆角的Android CardView显示灰色角 [英] Android CardView with rounded corners displays grey corners
问题描述
我正在用CardView扩展自定义布局. 圆角将按预期显示,但在角后面也会显示灰色背景.
I'm inflating a custom layout with CardView inside the layout. The rounded corners are displayed as expected but I also get grey background behind the corners.
代码很简单,使用具有拐角半径和背景颜色的CardView. 我尝试设置透明背景,但是不起作用.但是,如果我设置了另一种不透明颜色,它将显示在角落.
The code is simple, uses a CardView with corner radius and a background color. I've tried setting transparent background but doesn't work. However, if i set another opaque color, it is displayed in corners.
已附加代码.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="@android:color/transparent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="6dp"
app:cardElevation="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<TextView
android:id="@+id/tvProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/ivIcon"
android:layout_toStartOf="@+id/ivIcon"
android:background="@android:color/transparent"
android:padding="@dimen/elementPaddingSmall"
android:text="Initial Discussion"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black" />
<ImageView
android:id="@+id/ivIcon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="@color/lightBrown"
android:scaleType="centerInside"
android:src="@drawable/ic_checkmark_circle" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
结果:
推荐答案
由于阴影,您需要在cardview中留出空间以显示完整的阴影.将android:layout_margin="5dp"
添加到 CardView ,您将看到灰色"颜色是阴影.
It is because of shadow, you need to give space to cardview to show full shadow. Add android:layout_margin="5dp"
to CardView and you will see that the "grey" color is cut shadow.
解决方案正在向CardView添加app:cardUseCompatPadding="true"
,它将提供所需的间距.
Solution is adding app:cardUseCompatPadding="true"
to CardView and it will give needed spacing.
这篇关于带有圆角的Android CardView显示灰色角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!