Android 自定义背景xml文件
有没有可能使xml文件具有背景,其中将包含3条垂直的颜色线(黑色10 dp,白色匹配父项,黑色10 dp)Android 自定义背景xml文件,android,Android,有没有可能使xml文件具有背景,其中将包含3条垂直的颜色线(黑色10 dp,白色匹配父项,黑色10 dp) 我需要将其作为布局背景属性中的xml文件使用,因此我不能简单地将布局分成3个部分并对其着色。您可以使用9-patch generator创建9个补丁图像: 基本上,9-patch generator将接受任何大小的图像,并将创建资源来扩展图像和内容的特定区域。然后您可以轻松地导入它们。 链接:您可以使用9面片生成器创建9个面片图像: 基本上,9-patch generator将接受任何大小
我需要将其作为布局背景属性中的xml文件使用,因此我不能简单地将布局分成3个部分并对其着色。您可以使用9-patch generator创建9个补丁图像: 基本上,9-patch generator将接受任何大小的图像,并将创建资源来扩展图像和内容的特定区域。然后您可以轻松地导入它们。
链接:您可以使用9面片生成器创建9个面片图像: 基本上,9-patch generator将接受任何大小的图像,并将创建资源来扩展图像和内容的特定区域。然后您可以轻松地导入它们。
链接:我通常使用此代码添加水平线:
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
要添加垂直分隔符,请切换布局宽度和布局高度值。我通常使用此代码添加水平线:
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
若要添加垂直分隔符,请切换布局宽度和布局高度值。尝试此
创建一个background.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/id_view"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<View
android:id="@+id/id_view_one"
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="@android:color/black"/>
<View
android:id="@+id/id_view_two"
android:layout_below="@+id/id_view_one"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"/>
<View
android:id="@+id/id_view_three"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_alignParentBottom="true"
android:background="@android:color/black"/>
</RelativeLayout>
然后将background.xml包含在所需的xml文件中,如下所示
您的_activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/id_view"
android:layout_height="match_parent"
android:layout_width="match_parent">
<include layout="@layout/back"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
</RelativeLayout>
试试这个
创建一个background.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/id_view"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<View
android:id="@+id/id_view_one"
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="@android:color/black"/>
<View
android:id="@+id/id_view_two"
android:layout_below="@+id/id_view_one"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"/>
<View
android:id="@+id/id_view_three"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_alignParentBottom="true"
android:background="@android:color/black"/>
</RelativeLayout>
然后将background.xml包含在所需的xml文件中,如下所示
您的_activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/id_view"
android:layout_height="match_parent"
android:layout_width="match_parent">
<include layout="@layout/back"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
</RelativeLayout>
我已经用图片制作了(说来话长,但我只需要底角100%透明,中间灰色作为背景。但这应该行得通,所以我标记为answerI我已经用图片制作了(说来话长,但我只需要底角是100%透明的,中间是灰色作为背景。但这应该行得通,所以我标记为答案。)