Android Drawable Horizontal Line

2019-08-04 11:59发布

Is it possible to make line to be like this with xml? or there's some way to do that..?

enter image description here

I already made some drawable with shape but it's not really like i want

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners
        android:bottomLeftRadius="30dp"
        android:bottomRightRadius="30dp"
        android:topLeftRadius="0dp"
        android:topRightRadius="0dp" />
    <padding
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp" />
    <stroke
        android:width="0.8dp"
        android:color="@color/colorPrimaryDark" />
    <solid android:color="@android:color/transparent" />
</shape>

3条回答
Summer. ? 凉城
2楼-- · 2019-08-04 12:37
       <?xml version="1.0" encoding="utf-8"?>
        <inset xmlns:android="http://schemas.android.com/apk/res/android"
            android:insetLeft="-5dp"
            android:insetRight="-5dp"
            android:insetTop="-10dp">

       <shape android:shape="rectangle">
         <solid android:color="@android:color/transparent" />
           <stroke
             android:width="3dp"
             android:color="@color/colorPrimaryDark" />
       <corners
          android:bottomLeftRadius="25dp"
          android:bottomRightRadius="25dp" />
       </shape>
     </inset>
查看更多
神经病院院长
3楼-- · 2019-08-04 12:37

Try this

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <stroke
                android:width="1dp"
                android:color="#de0b0b" />
            <solid android:color="#ffffff" />
            <corners android:radius="20dp" />
        </shape>
    </item>

    <item
        android:bottom="5dp"
        android:top="0dp">
        <shape android:shape="rectangle">
            <stroke
                android:width="10dp"
                android:color="#ffffff" />
            <solid android:color="@android:color/transparent" />
            <corners android:radius="20dp" />
        </shape>
    </item>

</layer-list>

USE like this

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:gravity="center"
    android:background="#ffffff"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/test"
        android:text="Nilesh"
        android:gravity="center"
        android:layout_margin="@dimen/_5sdp"
        android:padding="@dimen/_5sdp">
    </TextView>

</LinearLayout>

OUTPUT

enter image description here

EDIT

Try this

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape
            android:shape="rectangle">

            <stroke android:width="1dp" android:color="#a032e4" />
            <solid android:color="#a032e4" />
            <corners android:radius="40dp"/>
        </shape>
    </item>

    <item android:bottom="4dp" >
        <shape
            android:shape="rectangle">
            <stroke android:width="2dp" android:color="#ffffff" />
            <solid android:color="#ffffff" />
            <corners android:radius="40dp"/>
        </shape>
    </item>

</layer-list>

USE LIKE THIS

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:gravity="center"
    android:background="#FFFFFF"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/test"
        android:layout_margin="20dp"
        android:padding="10dp"
        android:text="Nilesh Rathod"
        android:gravity="center" />

</LinearLayout>

OUTPUT

enter image description here

查看更多
Rolldiameter
4楼-- · 2019-08-04 13:02

We can create a drawable file also for this. May be helpful for someone.

Drawable file:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item>
    <shape android:shape="rectangle">
        <solid android:color="@android:color/white" />
    </shape>
</item>

<item>
    <shape android:shape="rectangle">
        <stroke
            android:width="5dp"
            android:color="@android:color/holo_blue_dark" />
        <solid android:color="@android:color/white" />
        <corners android:radius="20dp" />
    </shape>
</item>

<item android:bottom="25dp">
    <shape android:shape="rectangle">
        <stroke
            android:width="2dp"
            android:color="@android:color/white" />
        <solid android:color="@android:color/white" />
    </shape>
</item>

</layer-list>

Result :

enter image description here

查看更多
登录 后发表回答