Search code examples
androidxml-drawable

How to change the length of line in drawable resource?


I used the following xml code to draw a drawable image:

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

    <item>
        <shape
            android:shape="rectangle" >
            <corners
                android:topLeftRadius="30dp"
                android:topRightRadius="30dp"
                android:bottomLeftRadius="30dp"
                android:bottomRightRadius="30dp" />
            <solid
                 android:color="@color/black" />
            <padding
                 android:left="0dp"
                 android:top="0dp"
                 android:right="0dp"
                 android:bottom="0dp" />
            <size
                 android:width="60dp"
                 android:height="60dp" />
           </shape>
     </item>

     <item>
        <rotate
             android:fromDegrees="45"
             android:toDegrees="45"
             android:pivotX="50%"
             android:pivotY="50%">

            <shape
                android:shape="line">
                <stroke
                      android:width="2dp"
                     android:color="@color/white" />
               </shape>
          </rotate>
     </item>
</layer-list>

By the above code, I ended up with this image: enter image description here

Now I have to reduce the length of the white line in the center of the circle. i have used both <size android:height="40dp" /> and <size android:width="40dp" /> on the line and it doesn't do anything. So, how can I reduce the length of the line?


Solution

  • You can try this

    Add bottom,top,end & start to your item

     <item
            android:bottom="10dp"
            android:top="10dp"
            android:end="10dp"
            android:start="10dp">
            <rotate
                android:fromDegrees="45"
                android:toDegrees="45"
                android:pivotX="50%"
                android:pivotY="50%">
    
                <shape
                    android:shape="line">
                    <stroke
                        android:width="2dp"
                        android:color="@color/white" />
    
                </shape>
            </rotate>
        </item>