Android 常用布局文件:Android 常用 shape 整理

说明:大部分内容都是参考别的文章,这里做整理是为了以后的编程有实用的模板,可以即需即用。

1、圆

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

    <solid android:color="#c6c6c6" />
    <size
        android:width="50dp"
        android:height="50dp" />

</shape>
2、带圆角的长方形

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#b2b2b2" />
    <size
        android:width="50dp"
        android:height="30dp" />
    <corners android:radius="5dp" />
</shape>
3、带圆角的边框

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke
        android:width="1dp"
        android:color="#ff5a85" />
    <size
        android:width="50dp"
        android:height="30dp" />
    <corners android:radius="5dp" />
</shape>
4、状态切换

// selector_switch_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/btn_open" android:state_checked="true" />
    <item android:drawable="@drawable/btn_close" android:state_checked="false" />
</selector>
<ToggleButton
        android:layout_width="40dp"
        android:layout_height="20dp"
        android:background="@drawable/selector_switch_button"
        android:textOff="@null"
        android:textOn="@null" />
        
<Switch
        android:layout_width="40dp"
        android:layout_height="20dp"
        android:background="@drawable/selector_switch_button"
        android:textOff="@null"
        android:textOn="@null" />
5、水平进度条背景

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

    <!-- 设置progressbar的背景样式 -->
    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="20dp" />
            <solid android:color="#ffffff" />
            <stroke
                android:width="1dp"
                android:color="#32dcdc" />
        </shape>
    </item>

    <!-- 设置progressbar的进度条样式 -->
    <item android:id="@android:id/progress">
        <scale android:scaleWidth="100%">
            <shape>
                <corners android:radius="20dp" />
                <solid android:color="#32dcdc" />
            </shape>
        </scale>
    </item>

</layer-list>
    <ProgressBar
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:max="100"
        android:progressDrawable="@drawable/progress_bg" />
6、渐变色

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="0"
        android:endColor="#ff6060"
        android:startColor="#ff2434" />
</shape>
<gradient
        android:angle="integer"  // Integer,代表渐变颜色的角度,必须是45的整数倍,默认是 0,需要 android:type="linear"
        android:centerX="integer"  // Float,相对X的渐变位置(只有在 type 不为 linear 的情况下起作用)
        android:centerY="integer"  // Float,相对Y的渐变位置(只有在 type 不为 linear 的情况下起作用)
        android:centerColor="integer"  // Color,颜色渐变的中间颜色,主要用于多彩
        android:endColor="color"  // Color,颜色渐变的结束颜色
        android:startColor="color"  // Color颜色渐变的开始颜色
        android:gradientRadius="integer"  // Float,渐变颜色的半径,单位应该是像素点. 需要 android:type="radial"
        android:type=["linear" | "radial" | "sweep"]
        // linear 线性渐变,默认值
        // radial 放射性渐变(圆形渐变),起始颜色从 cenralX,centralY点开始
        // sweep 扫描式渐变(扇形渐变)
        android:useLevel=["true" | "false"] />  // 使用 LevelListDrawable 时就要设置
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值