我正在膨胀一个自定义布局,在布局中使用CardView。圆角显示如预期,但我也得到灰色背景后面的角。
代码很简单,使用的是具有角半径和背景颜色的CardView。我试过设置透明的背景,但不起作用。然而,如果我设置另一个不透明的颜色,它将显示在角。
密码是附加的。
<?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>
结果:
发布于 2018-01-15 02:59:28
这是因为阴影,你需要给予空间的卡纸,以显示完整的阴影。将android:layout_margin="5dp"
添加到CardView中,您将看到“灰色”颜色是裁剪阴影。
解决方案正在将app:cardUseCompatPadding="true"
添加到CardView中,它将给出所需的间距。
发布于 2018-01-15 03:10:47
试试这个..。
只需将0设置为app:cardElevation
.....
<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="0dp">
.....
或您可以调用cardView.setCardElevation(0)以编程方式禁用阴影。
发布于 2018-01-15 03:21:15
删除正在包装RelativeLayout
的父CardView
,您就可以继续了。就像这样:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
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"
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>
https://stackoverflow.com/questions/48261460
复制相似问题