Android设置虚线、圆角、渐变
有图又真相,先上图再说。
点击效果:
设置虚线:
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="line" >
- <stroke
- android:dashGap="3dp"
- android:dashWidth="6dp"
- android:width="1dp"
- android:color="#63a219" />
- <!-- 虚线的高度 -->
- <size android:height="1dp" />
- </shape>
其中,破折线的宽度为dashWith,破折线之间的空隙的宽度为dashGap,当dashGap=0dp时,为实线
设置圆角:
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="rectangle">
- <!-- 填充颜色 -->
- <solid android:color="#FFFFFF"></solid>
- <!-- 线的宽度,颜色灰色 -->
- <stroke android:width="1dp" android:color="#63a219"></stroke>
- <!-- 矩形的圆角半径 -->
- <corners android:radius="10dp" />
- </shape>
设置渐变填充和四个圆角半径:
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="rectangle">
- <!--分別對應上面左圆角的半径,上面右圆角的半径,下面左圆角的半径,下面右圆角的半径-->
- <corners
- android:topLeftRadius="0dp"
- android:topRightRadius="7dp"
- android:bottomLeftRadius="0dp"
- android:bottomRightRadius="7dp"/>
- <!--設置漸變-->
- <gradient android:startColor="#9cff00"
- android:endColor="#197600"
- android:angle="270"/>
- <stroke
- android:width="1dp"
- android:color="#63a219" />
- </shape>
设置渐变点击效果:
- <style name="list_item_top">
- <item name="android:clickable">true</item>
- <item name="android:focusable">true</item>
- <item name="android:paddingTop">10dip</item>
- <item name="android:paddingBottom">10dip</item>
- <item name="android:paddingLeft">10dip</item>
- <item name="android:paddingRight">10dip</item>
- <item name="android:gravity">center_vertical</item>
- <item name="android:background">@drawable/background_view_rounded_top</item>
- </style>
- <?xml version="1.0" encoding="UTF-8"?>
- <inset xmlns:android="http://schemas.android.com/apk/res/android"
- android:insetLeft="1.0px"
- android:insetRight="1.0px" >
- <selector>
- <item android:state_pressed="true">
- <shape>
- <gradient
- android:angle="270.0"
- android:endColor="@color/base_end_color_pressed"
- android:startColor="@color/base_start_color_pressed" />
- <corners
- android:bottomLeftRadius="0.0dip"
- android:bottomRightRadius="0.0dip"
- android:radius="2.0dip"
- android:topLeftRadius="10.0dip"
- android:topRightRadius="10.0dip" />
- <stroke
- android:width="1dp"
- android:color="#eededede" />
- </shape>
- </item>
- <item>
- <shape>
- <gradient
- android:angle="270.0"
- android:endColor="@color/base_end_color_default"
- android:startColor="@color/base_start_color_default" />
- <corners
- android:bottomLeftRadius="0.0dip"
- android:bottomRightRadius="0.0dip"
- android:radius="2.0dip"
- android:topLeftRadius="11.0dip"
- android:topRightRadius="11.0dip" />
- <stroke
- android:width="1dp"
- android:color="#eededede" />
- </shape>
- </item>
- </selector>
- </inset>
重新补充:好久没有关注自己的博客,没有注意到各位的评论,关于4.0以上设备虚线会变实线的问题,下面几位仁兄已经给出了答案,
代码中可以添加:
- line.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
xml中可以添加:
- android:layerType="software"
谢谢大家的参与!
源码免费下载地址:免费下载
http://download.csdn.net/detail/lan410812571/5925371
Android设置虚线、圆角、渐变的更多相关文章
- 【转】Android设置虚线、圆角、渐变
Android虚线圆角渐变 有图又真相,先上图再说. 点击效果: 设置虚线: <?xml version="1.0" encoding="utf-8" ...
- 44.Android之Shape设置虚线、圆角和渐变学习
Shape在Android中设定各种形状,今天记录下,由于比较简单直接贴代码. Shape子属性简单说明一下: gradient -- 对应颜色渐变. startcolor.endcolor就不多说 ...
- Android 设置进度条背景
Android 设置进度条背景 直接上代码 <ProgressBar android:id="@+id/progressBar" android:layout_width=& ...
- Android ActionBar标题和渐变背景
需要在AndroidManifest.xml中设置 android:theme="@style/Theme.AppCompat" 如果提示找不到,请按下图设置: 至于如何引入的方法 ...
- 【转】Android开发笔记——圆角和边框们
原文地址:http://blog.xianqu.org/2012/04/android-borders-and-radius-corners/ Android开发笔记——圆角和边框们 在做Androi ...
- Xamarin Android设置界面提示类型错误
Xamarin Android设置界面提示类型错误 错误信息:Integer types not allow (at ‘padding’ with value ’10’)Android界面属性的长度和 ...
- 设置UIImage 圆角
//设置UIImage圆角 @interface UIImage(UIRoundedRectImage) + (id) createRoundedRectImage:(UIImage*)image s ...
- 转:Android 设置屏幕不待机
本文转载于:http://blog.csdn.net/yudajun/article/details/7748760 Android设置支部待机有两种方法 第一种简单通过设置WindowManager ...
- I.MX6 android 设置 默认 动态桌面
/************************************************************************ * I.MX6 android 设置 默认 动态桌面 ...
随机推荐
- photoshop cc 版本安装失败解决办法
好久没有碰ps,看了下在ps版本都到cc了.忍不住也想尝试最新版本,但是安装出现了很多问题,导致我花了很多时间才搞定,现在分享给大家几点经验吧. Exit Code: Please see speci ...
- wpf样式绑定 行为绑定 事件关联 路由事件实例
代码说明:我要实现一个这样的功能 有三个window窗口 每个窗体有一个label标签 当我修改三个label标签中任意一个字体颜色的时候 其他的label标签字体颜色也变化 首先三个窗体不用 ...
- mysql数据类型——整型INT(m)
1.整形分为四种 tinyint smallint mediumint int bigint 注意: 右侧的取值范围是在未加unsigned关键字的情况下,如果加了unsigned,则最大值翻倍,如t ...
- PHP_EOL常量
PHP_EOL 换行符 unix系列用 \n windows系列用 \r\n mac用 \r PHP中可以用PHP_EOL来替代,以提高代码的源代码级可移植性 如: <?php echo PHP ...
- C# mvc3 mvc4 伪静态及IIS7.5配置
mvc3 mvc4路由配置 //单独路由 routes.MapRoute( name: "XXX", url: "Home/XXX.html/{id}&quo ...
- An endpoint configuration section for contract "serviceReferenc.service" could not be loaded
场景:有一个WCF应用,添加服务引用后,自动生成一个app.config文件,当调用WCF时,它抛出一个错误: An endpoint configuration section for contra ...
- temp 临时文件
放假了,放假了:http://blog.csdn.net/skywalker_only/article/details/17076851 nucht2.2.1爆出如下异常: Exception in ...
- "sessionFactory " or "hibernateTemplate " is required异常
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http:/ ...
- SharePoint DataFormWebPart 通过Caml和xslt聚合内容
以下是一个例子,SPDataSource用于查询内容,DatasourceMode属性指定查询范围(网站集,网站,列表),SelectCommand是Caml查询:Xsl展示内容,下面列子是用tabl ...
- iOS环形控制器、环形按钮
这两天接手了一个外包的UI,有一个环形的控制器,需求改啊改的:“安卓已经实现了……”,最讨厌这句了,最后做了一版,对方终于满意了,删掉其他的繁琐部分,留下控制器部分,大家看看,有更好的想法欢迎分享. ...