androidandroid-drawablelayer-list

Draw Line With Starting Circle


I am Using Drawable For Draw Horizontal Line With Starting Small Circle In android But The Circle Comes With Center Of the Horizontal Line. This is my code. android->res->drawable Folder.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:gravity="start">

        <shape
            android:innerRadius="0dp"
            android:shape="ring"
            android:thickness="6dp"
            android:useLevel="false">
            <solid android:color="@color/colorPrimary"/>
        </shape>

    </item>

    <item >
        <shape
            android:shape="line">
            <size
                android:width="200dp"
                android:height="200dp" />
            <stroke
                android:width="2dp"
                android:color="#0000FF" />
        </shape>
    </item>

Please Help me to solve this....


Solution

  • I think this will solve your problem.

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item >
            <shape
                android:shape="line">
                <size
                    android:width="200dp"
                    android:height="200dp" />
                <stroke
                    android:width="2dp"
                    android:color="#0000FF" />
            </shape>
        </item>
    
        <item android:gravity="start" android:left="-188dp">
    
            <shape
                android:innerRadius="0dp"
                android:shape="ring"
                android:thickness="6dp"
                android:useLevel="false">
                <solid android:color="@color/colorPrimary"/>
            </shape>
    
        </item>
    
    </layer-list>
    

    Also, to place this drawable in imageview then follow this code.

    <ImageView
        android:scaleType="fitXY"
        android:src="@drawable/test"
        android:layout_width="200dp"
        android:layout_height="15dp" />