android res之shape

应用场景

shape主要应用于为android控件制作如圆角,渐变,描边,填充等效果。

标签说明

  • corners 圆角
    android:Radius : 设置四个角的半径
    android:topLeftRadius :设置左上角的半径
    android:topRightRadius :设置右上角的半径
    android:bottomLeftRadius : 设置右下角的半径
    android:bottomRightRadius :设置左下角的半径

  • solid 填充
    android:color指定填充的颜色

  • strock 描边
    android:width: 描边的宽度,
    android:color :描边的颜色。
    我们还可以把描边弄成虚线的形式,设置方式为:
    android:dashWidth:虚线宽
    android:dashGap:隔开距离

  • gradient 渐变
    android:startColor:起始颜色
    android:endColor:结束颜色,
    android:angle:渐变角度,必须为45的整数倍。
    android:type=”linear”:线性渐变
    android:type=”radial”:径向渐变
    android:gradientRadius:径向渐变的半径

  • padding 间距
    设置上下左右四个方向的间隔。此处略!

shape使用

首先,在Drawable目录下新建btn_shape.xml的文件。

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <corners 
        android:topLeftRadius="15dp"
        android:topRightRadius="15dp"/><!-- 圆角 -->
    <solid android:color="@android:color/holo_blue_dark"/><!-- 填充 -->
    <stroke android:color="@android:color/holo_green_dark"/>
    <gradient android:startColor="@android:color/white"
        android:endColor="@android:color/black"
        android:angle="270"/>
</shape>

接着,在XML中引用:

<Button android:id="@+id/btn_shape"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        style="@style/ButtonStyle"
        android:background="@drawable/btn_shape"
        android:text="圆角按钮"/>

此外,在code中也是可以引用的,引用方法和设置背景图一样,可参考其它文章。下面附上效果图一张。

这里写图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值