参考: http://blog.csdn.net/lan410812571/article/details/9946991
设置虚线:
- <?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>
设置渐变填充和四个圆角半径: btn_corner_press:
- <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>
设置 按下 按钮 新建 一个 新的 drawable 然后 调用以上的drawable
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/btn_corner_press" /> <item android:state_focused="true" android:drawable="@drawable/btn_corner_press" /> <item android:drawable="@drawable/btn_corner_normal" /> </selector>
设置渐变点击效果:
- <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"
代码看附件:
相关推荐
可设置圆角背景边框的的按钮 通过调节色彩明度自动计算按下(pressed)状态颜色 Gradle repositories { maven { url "https://jitpack.io" } } dependencies { compile 'com.github.czy1121:roundbutton:1.1.0' ...
RCImageView 自定义圆角ImageView,带边框效果
首先,在res下面新建一个文件夹drawable,在drawable下面新建三个xml文件:shape_corner_down.xml、shape_corner_up.xml和shape_corner.xml,分别是下面两个角是圆角边框,上面两个角是圆角边框,四个角全部是圆角...
话不多说,上运行效果图 在drawable文件夹下 新建button_drawable.xml ... android:shape=rectangle> <!--设置背景色--> <solid android:color=#7457ED> <!--设置圆角--> <corners and
主要是分段时progressbar的颜色不一样 Canvas:...-- 控件类型 矩形,圆,圆角矩形 --> <!-- progress 进度条颜色 --> <!-- progress 背景 颜色 --> <!-- progress 分段
android-shape-imageview - 图片圆角、三角、五角、圆形、多角
-- 圆角 --> android:radius="20dp" android:topLeftRadius="20dp" android:topRightRadius="20dp" android:bottomRightRadius="0dp" android:bottomLeftRadius="0dp"/><!-- 设置圆角半径 --> <solid ...
MultiShapeView 支持圆角矩形,圆形自定义View
可以调节宽度,圆角角度,边框宽度,可调渐近色的竖起SeekBar
Android 通用圆角布局,快速实现圆角需求。 之前做项目的时候有圆角相关需求,在网上找了很多方案都不够满意,于是自己做了一个,目前已经使用了一段时间,更新了多个版本,我遇到的问题都进行了修复,并且添加了很...
--stl_indicatorCornerRadius : (指示器)动画下划线的圆角度数 --> <!--stl_indicatorThickness : (指示器)动画下划线的高度 --> <!--stl_underlineColor : 下划线的颜色 --> <!--stl_dividerThickness : ...
支持圆角、按压效果、边框大小颜色、每次再也不用写资源文件了
YXYDashLayer - 多彩的圆角矩形Dash边框
可以指定圆角的ViewGroup
Android设置虚线、圆角、渐变,详情请链接至: http://blog.csdn.net/lan410812571/article/details/9946991
本文实例讲述了Android开发圆角Button按钮实现过程,分享给大家供大家参考,具体内容如下 需求及效果图: 实现思路: 1、shape实现圆角 在drawable新建两个xml 文件, 这两个 xml文件用shape 实现了圆角效果。 Note:...
ShapeImageView 处理ImageView形状,原形圆角等 0. 源码地址 https://github.com/zhxhcoder/XImageView 1. 引用方法 compile 'com.zhxh:ximageviewlib:1.2' 2. 使用方法 举个栗子: 上面riv_height_to_width_ratio...
内容如标题,在QDialog上实现无边框,圆角,阴影,可拖拽大小,移动位置. 具体界面样式及实现细节参照我的同名博客文章.
android 圆角图标 和不规则圆角(边框.zip,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。