Shape color gradient, rounded corners, semi-rounded corners, border, fill

Insert image description here

1、shape:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <!--圆角-->
    <corners
        android:radius="5dp"
        android:topLeftRadius="30dp"
        android:bottomRightRadius="30dp"/>

    <!--填充颜色-->
    <solid android:color="#000"/>

    <!--边框-->
    <stroke
        android:color="#808080"
        android:width="2dp"/>

    <!--渐变-->
    <gradient
        android:startColor="#f52"
        android:centerColor="#f92"
        android:endColor="#fe2"
        android:angle="180"/>

</shape>

The gradient color offsets the fill color, so solid can be removed.

2. Regarding the angle parameter of gradient:

0 is from left to right

90 is from bottom to top

180 is from right to left

270 is from top to bottom

360==0

3. There is also a type parameter:

linear linear gradient (default)

radial circular gradient

sweep fan gradient

Gradient generally gives a start color and an end color, and then specifies the direction.

4. Semi-rounded corners on both sides:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners android:radius="999dp"/>

    <stroke
        android:width="1dp"
        android:color="@color/colorPrimary"/>

    <padding
        android:bottom="10dp"
        android:left="20dp"
        android:right="20dp"
        android:top="10dp"/>

</shape>

Guess you like

Origin blog.csdn.net/qq_32670947/article/details/130614844