1 常规切图适配

Android 常用shape图形绘制_适配

假设切图基于376×667的一倍屏幕设计,而要适配1080×1920的屏幕,导出三倍图存放于drawable-xxhdpi目录是适配最好的

2 shape图形绘制

简单的图形适配使用shape图形绘制,不仅屏幕适配性好,且空间占用小,以下常用的几种图形

渐变

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#00000000"
        android:angle="-90"
        android:centerY="50%"
        android:centerColor="#80000000"
        android:centerX="50%"
        android:endColor="#ff000000"/>
</shape>

长方体

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/color_green_bright" />
</shape>

长方体统一小圆角

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/color_green_bright" />
    <corners android:radius="4dp" />
</shape>

长方体固定方向圆角

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/color_green_bright" />
    <corners android:topLeftRadius="12dp"
        android:topRightRadius="12dp"
        android:bottomRightRadius="0dp"
        android:bottomLeftRadius="0dp"/>
</shape>

右半部带圆角的实体加线框

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/colorWhite"/>
    <corners android:topRightRadius="4dp" android:bottomRightRadius="4dp"/>
    <stroke android:width="1dip" android:color="@color/colorWhite"/>
</shape>

下半部带圆角的实体

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <solid android:color="@color/colorWhite" />
            <corners
                android:bottomLeftRadius="12dp"
                android:bottomRightRadius="12dp"
                android:topLeftRadius="0dp"
                android:topRightRadius="0dp" />
        </shape>
    </item>
    <item
        android:bottom="-2dp"
        android:left="-2dp"
        android:right="-2dp">
        <shape>
            <stroke
                android:width="1dp"
                android:color="@color/color_gray" />
        </shape>
    </item>
</layer-list>

带圆角的线框

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="90dp" />
    <stroke android:width="0.5dp" android:color="@color/color_green_bright"/>
</shape>

带线框的实体

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="100dp" />
    <stroke android:width="1dp" android:color="@color/color_green_bright"/>
    <solid android:color="@color/colorWhite"/>
</shape>

圆点

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
    <size android:width="10dp" android:height="10dp"/>
    <solid android:color="#aeadad" />
</shape>