编程知识 cdmana.com

Android uses Shape to implement simple triangles and circles, etc.

圆形

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
    <solid android:color="#000000" />
    <size android:width="80dp" android:height="80dp" />
</shape>
  • shape标签 :

    • 椭圆 oval
    • 矩形 rectangle
  • shape下的corners标签:
    * radius 四个圆角
    * topLeftRadius 左上角圆角
    * opRightRadius:  右上角的圆角
    *

  • shape下stroke标签:设置shape的外边界线

<stroke android:color="#FFFFFFFF" android:width="20dp" android:dashGap="10dp" android:dashWidth="10dp"/>
  • shape下的gradient标签 设置形状渐变
<gradient android:type="linear" android:angle="20"/>

三角形

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/shape_id">
        <!-- 正三角 -->
        <rotate android:fromDegrees="45" android:toDegrees="45" android:pivotX="-50%" android:pivotY="90%">
            <shape android:shape="rectangle">
                <solid android:color="#000000"/>
            </shape>
        </rotate>
    </item>
</layer-list>

版权声明
本文为[Ape Xiaoshuai 01]所创,转载请带上原文链接,感谢
https://cdmana.com/2022/218/202208060640061568.html

Scroll to Top