Android - rotate cuts off corners of shape

后端 未结 3 1734
被撕碎了的回忆
被撕碎了的回忆 2021-01-11 12:02

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

相关标签:
3条回答
  • 2021-01-11 12:32

    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.

    0 讨论(0)
  • 2021-01-11 12:51

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

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

    0 讨论(0)
  • 2021-01-11 12:55

    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

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题