如何更改可绘制资源中的线条长度?

How to change the length of line in drawable resource?

我使用以下 xml 代码绘制了可绘制图像:

<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>

通过上面的代码,我得到了这张图片:

现在我必须减少圆心白线的长度。我在线上同时使用了 <size android:height="40dp" /><size android:width="40dp" />,但它什么也没做。那么,我怎样才能减少线路的长度呢?

你可以试试这个

为您的项目添加底部、顶部、末端和开始

 <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>

使用此代码

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

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

    <item
        android:bottom="5dp"
        android:end="10dp"
        android:start="10dp"
        android:top="5dp">
        <rotate
            android:fromDegrees="45"
            android:pivotX="50%"
            android:pivotY="50%"
            android:toDegrees="45">

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

您可以调整矩形的填充以减少线条的宽度

你可以试试这个代码

<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="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />
        <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>