需要使用Shapes 在View
中绘制“X”,但X 的边缘必须锚定在 View 的左、上、右和底部。
像这样:
最佳答案
通过可绘制的 xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate
android:fromDegrees="135"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="135">
<shape android:shape="line">
<stroke android:width="1dp" android:color="@color/social_grey" />
</shape>
</rotate>
</item>
<item>
<rotate
android:fromDegrees="45"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="45">
<shape android:shape="line">
<stroke android:width="1dp" android:color="@color/social_grey" />
</shape>
</rotate>
</item>
</layer-list>
带填充:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="4dp"
android:right="4dp"
>
<rotate
android:fromDegrees="135"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="135">
<shape android:shape="line">
<stroke android:width="1dp" android:color="@color/social_grey" />
</shape>
</rotate>
</item>
<item
android:left="4dp"
android:right="4dp"
>
<rotate
android:fromDegrees="45"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="45">
<shape android:shape="line">
<stroke android:width="1dp" android:color="@color/social_grey" />
</shape>
</rotate>
</item>
</layer-list>
关于Android:使用形状绘制 "X",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11086985/