Shape美化

Shape美化


用途

使用shape来定义android控件的一些显示属性。

常见属性

<shape>
    <!--实心填充-->
    <solid android:color="#ffff77" />
    <!--渐变填充
    angle:渐变角度,必须是45的整数倍
    type:渐变模式,默认为线性渐变(linear)>>linear  radial  sweep
    gradientRadius:指定渐变半径,当type为径向渐变(radial)时需要定义该属性
    centerX:渐变的水平中心点,值为0-1.0
    centerY:渐变的垂直中心点,值同上
    centerColor:中心的颜色
    usesLevel:true || false 功能不详
    -->
    <gradient
        android:startColor="#ff8c00"
        android:endColor="#FFFFFF"
        android:angle="270" /> 
    <!--描边
    dashWidth:一个横线的宽度
    dashGap:每个横线间隔开的距离
    -->
    <stroke
        android:width="2dp"
        android:color="#000000" />
    <!--圆角
    topRightRadius:右上角的圆角弧度
    bottomLeftRadius  topLeftRadius(此处指的是你所看到的右下角)  bottomRightRadius
    -->
    <corners
        android:radius="2dp" />
    <!--间距-->
    <padding
        android:left="10dp"
        android:top="10dp"
        android:right="10dp"
        android:bottom="10dp" />
    <!--背景大小-->
    <size 
        android:width="30dp"
        android:height="45dp" />
</shape>

实例

shape_btn_test.xml

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TestShapeButton"
    android:background="@drawable/btn_selector"
    />

btn_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" >
        <shape>
            <gradient
                android:startColor="#ff8c00"
                android:endColor="#FFFFFF"
                android:type="radial"
                android:gradientRadius="50" />
            <stroke
                android:width="2dp"
                android:color="#dcdcdc"
                android:dashWidth="5dp" 
                android:dashGap="3dp" />
            <corners
                android:radius="2dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>

    <item android:state_focused="true" >
        <shape>
            <gradient
                android:startColor="#ffc2b7"
                android:endColor="#ffc2b7"
                android:angle="270" />
            <stroke
                android:width="2dp"
                android:color="#dcdcdc" />
            <corners
                android:radius="2dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>

    <item>       
        <shape>
            <solid android:color="#ff9d77"/>
            <stroke
                android:width="2dp"
                android:color="#fad3cf" />
            <corners 
                android:topRightRadius="5dp"
                android:bottomLeftRadius="5dp"
                android:topLeftRadius="0dp"
                android:bottomRightRadius="0dp"
            />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
</selector>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值