Monday, 29 June 2015

Android dot line





Horizontal

Create xml (view_line_dotted.xml):
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:bottom="-1dp"
            android:left="-1dp"
            android:right="-1dp"
            android:top="0dp">

            <shape android:shape="rectangle">
                <stroke
                    android:width="1dp"
                    android:color="#ffff0017"
                    android:dashGap="3dp"
                    android:dashWidth="1dp" />

                <solid android:color="@android:color/transparent" />

                <padding
                    android:bottom="10dp"
                    android:left="10dp"
                    android:right="10dp"
                    android:top="10dp" />
            </shape>
        </item>
</layer-list>
Set as background of your view:
<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@drawable/view_line_dotted" />

Vertical

Horizontal dot line is fine, but vertical I can't.


I tried "line", "rectangle." all fault.

People said it can be done by:

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="90"
    android:toDegrees="90"
    android:drawable="@drawable/horizontal_line" />

However, it doesn't work.


my solution is:






in your layout:

verital:
<View    android:layout_width="1dp"    android:layout_height="fill_parent"    android:background="@drawable/vertical_dotted" />

Horizontal

<View    android:layout_width="match_parent"    android:layout_height="2dp"    android:background="@drawable/horizontal_dotted" />


in drawable:

dotted.xml:

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

    <solid android:color="@android:color/transparent"/>
    <stroke        android:width="1dp"        android:color="#ff6c6c6c"        android:dashGap="3dp"        android:dashWidth="1dp" />
</shape>



horizontal_dotted.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item        android:bottom="-1dp"        android:left="-1dp"        android:right="-1dp"        android:top="0dp" android:drawable="@drawable/dotted">
    </item>
</layer-list>


vertical_dotted.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item        android:bottom="-1dp"        android:left="-1dp"        android:right="0dp"        android:top="-1dp" android:drawable="@drawable/dotted">

    </item>
</layer-list>








useful links


http://stackoverflow.com/questions/2658772/vertical-line-using-xml-drawable


http://stackoverflow.com/questions/20583298/creating-horizontal-and-vertical-dotted-lines-in-android

http://stackoverflow.com/questions/6103713/how-do-i-make-a-dotted-dashed-line-in-android



No comments:

Post a comment