Android笔记----Shape标签使用

在Android界面的设计过程中,有时候以后的控件的外形并不符合我们的需要,有时候我们就想要改变控件的外形,就会使用到Shape标签定义控件的外形


1、<Shape /> 标签属性

  Shape标签有六个属性:

       1、<corners />:四角轮廓的弯曲半径

       2、<stroke  />:边界围栏,设置边界宽度、边界类型(线状、破折状)

       3、<gradient />:梯度颜色填充,设置多级背景颜色填充背景(start、center、end)。

       4、<size />   :外形大小

       5、<padding /> : 边距填充

       6、<solid /> :单色


2、示例

   XML布局文件

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- 四角弧度半径
      radius:四角弧度半径
      topLeftRadius:左上角弧度半径
      topRightRadius:右上角弧度半径
      bottomRightRadius:右下角弧度半径
      bottomLeftRadius:左下角弧度半径-->
    <corners
        android:radius="20dp" 
        />
    <!-- 边界宽度
      width:边界厚度
      dashWidth:破折长度(边界由有间距的破折线条组成)
      dashGap: 破折间距
      color: 边界颜色-->
    <stroke 
        android:width="3dp"
        android:dashWidth="5dp"
        android:dashGap="5dp"
        android:color="@android:color/darker_gray"/>
    <!-- 梯度颜色 
        gradientRadius:半径折射模式每个梯度的宽度;
        startColor:起始梯度颜色
        centerColor:中间梯度颜色
        endColor:后段梯度颜色
        type :梯度填充类型:linear(线性填充)|radial(半径辐射梯度填充)|sweep(环形扫射过度) 
        centerX:填充中心横坐标
        centerY:填充中心纵坐标
        -->
    <gradient 
        android:startColor="@android:color/holo_blue_bright"
        android:centerColor="@android:color/holo_green_dark"
        android:endColor="@android:color/holo_orange_light"
        android:gradientRadius="50dp"
        android:type="radial"
        android:centerX="0.5"
        android:centerY="0.5"
        />
    <!-- Shape大小
        width: 宽度
        height:高度 -->
    <size 
        android:width="80dp"
        android:height="80dp"/>
    <!-- 边距填充
        left:距左边界距离
        right:距有边界距离
        top: 距上边界距离
        bottom: 距下边界距离 -->
    <padding 
        android:left="2dp"
        android:top="2dp"
        android:right="2dp"
        android:bottom="2dp"/>
    <solid />
</shape>
 
 

          

     效果图:

          


你可能感兴趣的:(android,前端,标签,控件,界面)