Android形状xml如下图所示

时间:2016-09-30 06:35:56

标签: android xml shape

i need to create run in my xml

我如何在xml(可绘制文件夹)中创建该形状。

2 个答案:

答案 0 :(得分:1)

drawable_line.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <gradient
        android:startColor="@android:color/black"
        android:centerColor="@android:color/white
        android:endColor=  "@android:color/black"
        android:angle="360"
        />
</shape>

将其作为view

添加到您的布局中
<View
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:layout_marginRight="20dp"
            android:layout_marginLeft="20dp"
            android:background="@drawable/drawable_line" />

答案 1 :(得分:0)

在activity_main中添加这些:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:gravity="center"
        android:background="@android:color/black"
        android:layout_width="match_parent"
        android:layout_height="80dp">

    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:background="@drawable/line" />
    </LinearLayout>
</LinearLayout>

并创建可绘制的res文件:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="360"
        android:centerColor="@android:color/white"
        android:endColor="@android:color/black"
        android:startColor="@android:color/black" />
</shape>