CardView 边框没有变化
CardView border does not change
在我的可绘制文件夹中
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 边框没有 change.What 我做错了吗,我希望 cardview 提升到相对布局之上,但即使在添加提升后也不会发生 attribute.Please 帮助
我希望我的汽车视图看起来像这样带边框
enter image description here
您应该使用 app:cardBackgroundColor
更改 CardView
的背景而不影响 CardView
的高度。
如果您使用此 属性,您将失去 CardView 的高度:android:background
<?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>
通过删除相对布局进行检查,卡片视图将提升。
在我的可绘制文件夹中
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 边框没有 change.What 我做错了吗,我希望 cardview 提升到相对布局之上,但即使在添加提升后也不会发生 attribute.Please 帮助 我希望我的汽车视图看起来像这样带边框 enter image description here
您应该使用 app:cardBackgroundColor
更改 CardView
的背景而不影响 CardView
的高度。
如果您使用此 属性,您将失去 CardView 的高度:android:background
<?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>
通过删除相对布局进行检查,卡片视图将提升。