在Android中常常会使用shape来定义控件的一些显示属性,那么怎么来用那,今天我们就来看一些shape的使用,大家看完这篇以后就会对shape有了大体的了解,下面的是稍作总结请大家仔细的观看:

<shape>

<!-- 实心 -->

<solid android:color="#ff9d77"/>

<!-- 渐变 -->

<gradient

android:startColor="#ff8c00"

android:endColor="#FFFFFF"

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>

 solid:实心,就是填充的意思


       android:color指定填充的颜色

       gradient:渐变
       android:startColor和android:endColor分别为起始和结束颜色,ndroid:angle是渐变角度,必须为45的整数倍。
       另外渐变默认的模式为android:type="linear",即线性渐变,可以指定渐变为径向渐变,android:type="radial",径向渐变需要指定半径                                      android:gradientRadius="50"。

 stroke:描边
       android:width="2dp" 描边的宽度,android:color 描边的颜色。

我们还可以把描边弄成虚线的形式,设置方式为:
       android:dashWidth="5dp"
       android:dashGap="3dp"
       其中android:dashWidth表示'-'这样一个横线的宽度,android:dashGap表示之间隔开的距离。

corners:圆角
       android:radius为角的弧度,值越大角越圆。
       我们还可以把四个角设定成不同的角度,方法为:

  

<corners

android:topRightRadius="20dp" 右上角

android:bottomLeftRadius="20dp" 右下角

android:topLeftRadius="1dp" 左上角

android:bottomRightRadius="0dp" 左下角

/>

    这里有个地方需要注意,bottomLeftRadius是右下角,而不是左下角,这个有点郁闷,不过不影响使用,记得别搞错了就行。
       还有网上看到有人说设置成0dp无效,不过我在测试中发现是可以的,我用的是2.2,可能修复了这个问题吧,如果无效的话那就只能设成1dp了。

 padding:间隔
       这个就不用多说了,XML布局文件中经常用到。

大体的就是这样,以下是一个使用的具体示例:用在Selector中作为Button的背景,分别定义了按钮的一般状态、获得焦点状态和按下时的状态,具体代码如下:

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="TestShapeButton"

android:background="@drawable/button_selector"

/>

我们来看看main.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>

运行效果:

转自:http://yanweimin7.iteye.com/blog/1021042

android Shape使用(转)的更多相关文章

  1. android shape使用总结

    今天使用到shape,这个里面有很多属性,在这里我记录一下各个属性的使用的情况以及所代表的意思 <?xml version="1.0" encoding="utf- ...

  2. android:shape

    android:shape=["rectangle" | "oval" | "line" | "ring"] shape ...

  3. Android shape的使用(圆角矩形)

    <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http: ...

  4. android shape详解

    shape--> shape属性: rectangle: 矩形,默认的形状,可以画出直角矩形.圆角矩形.弧形等 solid: 设置形状填充的颜色,只有android:color一个属性 andr ...

  5. android shape(如自定义Button)

    Shape 前言:有时候会去自己去画一些Button的样式来展现在UI当中,其中主要用到的就是Shape 先来看一段代码: <?xml version="1.0" encod ...

  6. android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)

    shape使用.渐变色.分割线.边框.半透明.半透明阴影效果. 首先简单了解一下shape中常见的属性.(详细介绍参看  api文档 ) 转载请注明:Rflyee_大飞: http://blog.cs ...

  7. Android Shape画圆,矩形

    画圆环代码如下: 画圆环,外边的边界宽度大一点即可: <?xml version="1.0" encoding="utf-8"?> <shap ...

  8. ANDROID SHAPE画圆形背景_ANDROID实现角标布局

    ANDROID SHAPE画圆形背景_ANDROID实现角标布局 <?xml version="1.0" encoding="UTF-8"?> &l ...

  9. android shape总结 和控制的风格定制

    1:shape总结 1):shape文件是放置在drawable文件下的.res/drawable/filename.xml. 2):shape类型:android:shape. 一共同拥有四种:re ...

  10. [转]Android Shape渲染的使用(经典,学习研究不后悔)

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://mzh3344258.blog.51cto.com/1823534/1215749 ...

随机推荐

  1. AtCoder Regular Contest 099

    AtCoder Regular Contest 099 C - Minimization 题意 题意:给出一个n的排列.每次操作可以使一段长度为K的连续子序列变成该序列的最小数.求最少几次使得整个数列 ...

  2. php异常处理笔记

    <?php header("Content-type:text/html;charset=utf-8"); // try // { // //业务处理 错误时抛出异常. // ...

  3. POJ - 2785 - 4 Values whose Sum is 0 - 二分折半查找

    2017-08-01 21:29:14 writer:pprp 参考:http://blog.csdn.net/piaocoder/article/details/45584763 算法分析:直接暴力 ...

  4. Gulp实例(包括环境搭建的自动检测)

    # Gulp实例(包括环境搭建的自动检测) Gulp是一个自动化构建工具,开发者可以使用它在项目开发过程中自动执行常见任务.下面我将完成如下的功能点并且附上源码: CSS文件打包 less文件打包 s ...

  5. ButterKnife使用详谈

    (1)ButterKnife是什么? 在开发过程中,我们总是会写大量的findViewById和点击事件,像初始view.设置view监听这样简单而重复的操作让人觉得特别麻烦,当然不会偷懒的程序员不是 ...

  6. LeetCode第[69]题(Java):Sqrt(x)

    题目:求平方根 难度:Easy 题目内容: Compute and return the square root of x, where x is guaranteed to be a non-neg ...

  7. python学习笔记(conf配置文件)

    在优化自己的框架中发现一个问题 有很多参数在很多类中都要使用.是否有什么功能可以帮助优化这些功能 这里我就想到 conf配置文件.整理了下资料 总结下内容如下 #!/usr/bin/env pytho ...

  8. 使用科大讯飞时碰上的问题(unity调用Android)

    使用科大讯飞的时候公司已经有人配置好了Android项目,由于装机量的限制,所以基本上要更换里面的资源和更改app_id,然而在unity那边调用的时候总是出现各种各样的问题,特此记录下来 1.唤醒未 ...

  9. JQuery 全选 取消

    $('#chkAllProp').click(function () { $("input[id*='chkSelect']").prop("checked", ...

  10. combobox里面显示checkbox

    看了http://www.cnblogs.com/yubinfeng/p/4463418.html这篇博客,我添加了部分代码,以便在最后获取combobox的value时可以拿到一个数组. HTML代 ...