Vertical line using XML drawable

前端 未结 15 575
无人及你
无人及你 2020-11-27 09:57

I\'m trying to figure out how to define a vertical line (1dp thick) to be used as a drawable.

To make a horizontal one, it\'s pretty straightforward:



        
相关标签:
15条回答
  • 2020-11-27 10:24

    I think this is the simplest solution:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item
            android:gravity="center">
            <shape android:shape="rectangle">
                <size android:width="1dp" />
                <solid android:color="#0000FF" />
            </shape>
        </item>
    
    </layer-list>
    
    0 讨论(0)
  • 2020-11-27 10:27
    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item
            android:bottom="-3dp"
            android:left="-3dp"
            android:top="-3dp">
    
            <shape android:shape="rectangle">
                <solid android:color="@color/colorPrimary" />
                <stroke
                    android:width="2dp"
                    android:color="#1fc78c" />
            </shape>
    
        </item>
    
    </layer-list>
    
    0 讨论(0)
  • 2020-11-27 10:28

    You can use a shape but instead of a line make it rectangle.

    android:shape="rectangle">
    <stroke
        android:width="5dp"
        android:color="#ff000000"
        android:dashGap="10px"
        android:dashWidth="30px" />
    

    and In your layout use this...

    <ImageView
        android:layout_width="7dp"
        android:layout_height="match_parent"
        android:src="@drawable/dashline"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layerType="software"/>
    

    You might have to play with the width, depending on the size of the dashes, to get it into a single line.

    Hope this helps Cheers

    0 讨论(0)
提交回复
热议问题