Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - rotate cuts off corners of shape

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>

enter image description here

like image 222
uesports135 Avatar asked Oct 26 '14 19:10

uesports135


3 Answers

This was already solved here: Diamond shape xml background for android view

Just change fill color and stroke width according to your needs.

like image 93
Luigi_Papardelle Avatar answered Nov 03 '22 13:11

Luigi_Papardelle


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

like image 31
Ali Hassan Avatar answered Nov 03 '22 13:11

Ali Hassan


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.

like image 28
AlexVPerl Avatar answered Nov 03 '22 11:11

AlexVPerl