在我的drawable文件夹中
cardeviewborder.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/colorAccent"/>
<stroke android:width="3dip" android:color="#B1BCBE" />
<corners android:radius="20dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>
在布局文件夹
中<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="@android:color/white"
android:layout_height="wrap_content"
android:padding="10dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:layout_gravity="center"
android:background="@drawable/cardviewborder"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/listitemtaskname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textSize="25sp"
android:textStyle="bold"
tools:text="Hi" />
<TextView
android:id="@+id/listitemdatedetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textSize="15sp"
tools:text="By" />
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
CardView边框不会改变。我做错了什么,我希望cardview提升到relativelayout之上,但即使添加了提升属性也不会发生。请帮助 我希望我的carview看起来像这样的边框 enter image description here
答案 0 :(得分:0)
您应该使用app:cardBackgroundColor
更改CardView
的背景,而不会影响CardView
的高程。
如果您使用此属性,则会丢失CardView的高程:android:background
答案 1 :(得分:0)
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/listitemtaskname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textSize="25sp"
android:textStyle="bold"
tools:text="Hi" />
<TextView
android:id="@+id/listitemdatedetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textSize="15sp"
tools:text="By" />
</LinearLayout>
</android.support.v7.widget.CardView>
通过删除相对布局进行检查,cardview将提升。