初学Android时,一直有一个疑惑:为什么Android里的图片资源是放在一个叫drawable的文件夹里呢?为什么这个图片资源的文件夹不用images或bitmaps之类的名称呢?
因为Android可以“绘制”的并不只有png、jpg之类的图片,还有xml文件,Android中的shape就是一样一个可绘制的xml。虽然之前也有接触过Shape,但如今重拾Shape时才恍然明白。

 

<shape
   android:shape = "rectangle" >
    <!-- 大小 -->
    <size
       android:width = "50dp"
       android:height = "50dp" />

    <!-- 实心 -->
    <solid android:color = "#FFFF" />

    <!-- 渐变 -->
    <gradient 
       android:startColor = "#FFFF"
       android:endColor = "#0000"
       android:angle = "90"/>

    <!-- 描边 -->
    <stroke
       android:width = "2dp"
       android:color = "#777" />

    <!-- 圆角 -->
    <corners
       android:radius =" 2dp" />

    <!-- 内边距 -->
    <padding
       android:left = "10dp"
       android:top = "10dp"
       android:right = "10dp"
       android:bottom = "10dp" />
</shape>

<shape>

  • android:shape 形状,可选值:rectangle(矩形)| oval(椭圆)| linear(线型)| ring(弧形)
<size> 大小
  • android:width 宽度
  • android:height 高度
<solid> 实心
  • android:color 填充的颜色 ARGB
<gradient> 渐变
  • android:startColor 渐变的起始色
  • android:centerColor 渐变的中间色
  • android:endColor 渐变的终止色
  • android:type 渐变的类型 可选值:linear(线性) | radial(径向) | sweep(梯度)
  • android:angle 渐变的角度 必须为45的整数倍,仅在type=”linear”有效
  • android:gradientRadius 径向半径,仅在type=”radial”有效,且必须指定
<stroke> 描边
  • android:width 描边宽度
  • android:color 描边颜色
  • android:dashWidth 虚线宽度
  • android:dashGap 虚线间隔宽度

需要同时设置dashWidth和dashGap属性都为非0dp,才为虚线边框。

<corners> 圆角
  • android:Radius 圆角的半径
  • android:topLeftRadius 左上角的半径
  • android:topRightRadius 右上角的半径
  • android:bottomLeftRadius 右下角的半径
  • android:bottomRightRadius 左下角的半径

同时设置五个属性,则Radius属性无效

<padding> 内边距
  • android:left 左内边距
  • android:top 上内边距
  • android:right 右内边距
  • android:bottom 下内边距
欢迎转载《Android Shape》,转载请注明文章地址
http://blog.minesites.cn/blog/android-shape/
arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()


    留言列表 留言列表

    發表留言