I wish to make a diamond as a resource file so I am rotating a square in order to do so. The problem is that the corners seem to be getting cut off, making a hexagon instead. Also as a side note, I'd like to stretch it vertically if that's possible.
<?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>
This was already solved here: Diamond shape xml background for android view
Just change fill color and stroke width according to your needs.
I am searching for rotate the square this help
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="20dp"
android:left="20dp"
android:right="20dp"
android:top="20dp">
<rotate
android:drawable="@color/colorAccent"
android:fromDegrees="-135"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="-45"
android:visible="true">
<shape android:shape="rectangle">
<solid android:color="@color/colorPrimaryDark" />
<corners android:radius="15dp" />
<size
android:width="90dp"
android:height="90dp" />
<solid
android:angle="45"
android:endColor="@color/colorAccent"
android:gradientRadius="34"
android:startColor="@color/colorPrimary" />
</shape>
</rotate>
</item>
</layer-list>
But I follow some ratio relationship for height and width 90dp and item top ,bottom,left ,right are 20dpenter image description here
Heres how:
**<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>
Adjust Left/Right/Top/Bottom as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With