我希望将钻石制作为资源文件,因此我要旋转一个正方形。问题在于拐角似乎被切除,取而代之的是六角形。另外请注意,如果可能的话,我想垂直拉伸它。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate
android:fromDegrees="45"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="45"
>
<shape android:shape="rectangle">
<size
android:height="40dp"
android:width="40dp" />
<solid
android:color="@color/level_1_color" />
</shape>
</rotate>
</item>
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9TWmhEUi5wbmcifQ==” alt =“在此处输入图像描述”>
这里如何:
**<item android:left="5dp" android:right="5dp" android:top="5dp" android:bottom="5dp">**
<rotate
android:fromDegrees="45"
android:toDegrees="45" >
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="@color/sym_orange_bdfm"/>
<size
android:width="23dp"
android:height="23dp"/>
</shape>
</rotate>
</item>
根据需要调整左/右/上/下。
此问题已在此处解决:Diamond shape xml background for android view
只需根据需要更改填充颜色和笔触宽度。