Android 如何将两个xml文件一起设置为背景
我希望cardview周围有涟漪效应和边框,我有两个xml文件 一个用于边框,另一个用于撕裂效果,那么如何将我的cardview设置为背景 这是我的密码 xml(v17)Android 如何将两个xml文件一起设置为背景,android,android-studio,Android,Android Studio,我希望cardview周围有涟漪效应和边框,我有两个xml文件 一个用于边框,另一个用于撕裂效果,那么如何将我的cardview设置为背景 这是我的密码 xml(v17) xml(v21) 这是我的cardview,我想把两者结合起来 cardview.xml <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView android:layout
xml(v21)
这是我的cardview,我想把两者结合起来
cardview.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
android:layout_marginTop="10dp"
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:background="@drawable/shape"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<TextView
android:textColor="#000"
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="20sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
如何将两个文件设置在一起?不支持布局中的bcz两个背景。请帮帮我。创建一个带有层列表的新XML,并在其中添加您的形状和波纹就像Iulian Popescu所说的,您可以使用层列表,这似乎是最好的选择。但是,如果您坚持将它们分开,那么您就可以使用canvas将它们合并到代码中。 如果要使用此技术,请使用以下主题:
使用图层列表进行操作。cardview_style.xml
<?xml version="1.0" encoding="UTF-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<stroke android:width="1dp" android:color="#1B5E20" />
<corners android:radius="2dp"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>
</item>
<item>
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorControlHighlight">
<item
android:id="@android:id/mask"
android:drawable="@android:color/white"></item>
</ripple>
</item>
然后将以下文件添加到背景属性。检查此链接我的形状的角半径为100dp,即圆形角。如何在出现波纹的情况下显示相同的内容。涟漪看起来像一个长方形。很好的解决方案。谢谢
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
android:layout_marginTop="10dp"
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:background="@drawable/shape"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<TextView
android:textColor="#000"
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="20sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<?xml version="1.0" encoding="UTF-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<stroke android:width="1dp" android:color="#1B5E20" />
<corners android:radius="2dp"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>
</item>
<item>
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorControlHighlight">
<item
android:id="@android:id/mask"
android:drawable="@android:color/white"></item>
</ripple>
</item>