android中shape 的使用
android 开发中 对于 shape 和 selector的使用,一直都不是很熟练, 记录一下.便于以后参考.
举个项目中例子图

对于上面的2个radiobutton ,背景我们可以让美工做一个.9图来实现. 但是最后还是自己用shape 搞一下.
按钮布局如下:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/space_8"
android:orientation="horizontal"> <RadioGroup
android:id="@+id/order_rg"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="@dimen/space_8"
android:layout_marginRight="@dimen/space_8"
android:orientation="horizontal">
//默认选中
<RadioButton
android:id="@+id/rb_left"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_weight="1"
android:background="@drawable/fg_order_rb_selector"
android:button="@android:color/transparent"
android:checked="true"
android:drawablePadding="@dimen/space_4"
android:gravity="center"
android:text="投资记录"
android:textColor="@drawable/fg_order_text_selector"
android:textSize="@dimen/txt_14" />
//默认不选中
<RadioButton
android:id="@+id/rb_right"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_weight="1"
android:background="@drawable/fg_order_rb_selector1"
android:button="@null"
android:drawablePadding="@dimen/space_4" android:text="提现记录"
android:gravity="center"
android:textColor="@drawable/fg_order_text_selector"
android:textSize="@dimen/txt_14" />
</RadioGroup>
</LinearLayout>
里面用到2个 selector , 1个是文字背景选择器fg_order_text_selector,1个RadioButton颜色背景选择器fg_order_rb_selector1
2个RadioButton用到的文字选择器如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/white" android:state_checked="true"/> //白色
<item android:color="@color/black" android:state_checked="false"/>//黑色
</selector>
第一个RadioButton用到的颜色背景选择器 :fg_order_rb_selector.xml , rb_left.xml , rb_right.xml 如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/rb_left"
android:state_checked="true"
android:state_enabled="true"
/> <item
android:drawable="@drawable/rb_right"
android:state_checked="false"
android:state_enabled="false"/>
</selector>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 圆角 -->
<corners android:bottomLeftRadius="6dp" android:topLeftRadius="6dp" />
<stroke android:color="@color/wave_bg" android:width="1dp" />
<!--内部填充色-->
<solid android:color="@color/wave_bg" />
</shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 圆角 -->
<corners android:bottomLeftRadius="6dp" android:topLeftRadius="6dp" /> <stroke android:color="@color/wave_bg" android:width="1dp" />
<!--内部填充色-->
<solid android:color="@color/white"/>
</shape>
第二个RadioButton用到的颜色背景选择器 :fg_order_rb_selector1.xml , rb_left1.xml , rb_right1.xml 如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/rb_left1"
android:state_checked="true"
android:state_enabled="true"
/> <item
android:drawable="@drawable/rb_right1"
android:state_checked="false"
android:state_enabled="false"/>
</selector>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 圆角 -->
<corners android:bottomRightRadius="6dp" android:topRightRadius="6dp" /> <stroke android:color="@color/wave_bg" android:width="1dp" />
<!--内部填充色-->
<solid android:color="@color/wave_bg" />
</shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 圆角 -->
<corners android:bottomRightRadius="6dp" android:topRightRadius="6dp" /> <stroke android:color="@color/wave_bg" android:width="1dp" />
<!--内部填充色-->
<solid android:color="@color/white"/>
</shape>
以上就是 全部资源文件了. 没有用到任何一张图.
参考博文:http://blog.csdn.net/zzy7075/article/details/42235947
android中shape 的使用的更多相关文章
- Android中shape属性详解
一.简单使用 刚开始,就先不讲一堆标签的意义及用法,先简单看看shape标签怎么用. 1.新建shape文件 首先在res/drawable文件夹下,新建一个文件,命名为:shape_radius.x ...
- 【Android 界面效果19】Android中shape的使用
Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shape有了大体的了解,稍作总结: 先看下面的代码: <shape> ...
- Android 中 shape 图形的使用
转载于:http://kofi1122.blog.51cto.com/2815761/521605 Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shap ...
- Android 中shape的使用(圆角矩形)
一.在res/drawable文件夹下创建一个名为gradient_box的xml文件: <?xml version="1.0" encoding="utf-8&q ...
- 转 Android中shape中的属性大全
<shape> <!-- 实心 --> <solid android:color="#ff9d77"/&g ...
- Android中shape中的属性大全
---恢复内容开始--- <shape> <!-- 实心 --> <solid android:color="#ff9d77"/> <!- ...
- android中shape的属性
<shape> <!– 实心 –> <solid android:color=”#ff9d77″/> <!– 渐变 –> <gradient an ...
- Android中shape的使用 (转载)
转自:http://blog.csdn.net/ekeuy/article/details/12349853 在看很多开源代码中都使用到了shape,我看代码的时候一般都一带而过了,没有仔细去研究,这 ...
- android中shape的使用(android:angle小解)
本文参考http://kofi1122.blog.51cto.com/2815761/521605和http://blog.csdn.net/qizi329/article/details/63098 ...
随机推荐
- RE最全面的正则表达式----字符验证
二.校验字符的表达式汉字:^[一-彪]{0,}$英文和数字:^[A-Za-z0-9]+$ 或 ^[A-Za-z0-9]{4,40}$长度为3-20的所有字符:^.{3,20}$由26个英文字母组成的字 ...
- springboot自动配置源码解析
springboot版本:2.1.6.RELEASE SpringBoot 自动配置主要通过 @EnableAutoConfiguration, @Conditional, @EnableConfig ...
- java后端开发面经 数据库相关
小姐姐:怎么理解感情中的付出和回报? 你答:有这样一个故事,讲的是一个小男孩和一个小女孩,这个小男孩呢,用很多好玩石头,而这个小女孩呢,有好多好吃的糖果,有一天,他们相互约定:小男孩用所有的石头交互小 ...
- 敏捷开发--必备工具Jira&Confluence学习视频
敏捷开发必备工具:Jira+confluence,完美组合. 入门培训视频,内含Jira, Confluence, BigGantt, Zephyr, Tempo, Question, ScriptR ...
- 程序与CPU
CPU中共有四大组件: 寄存器 控制器 运算器 时钟 寄存器:存取数值(存东西的) 控制器:负责将内存(寄存器)中的数据进行读入和写出(控制寄存器 协调者) 运算器:里面是逻辑运算单元,协助寄存器和控 ...
- Linux浏览创建文件
pwd:打印当前工作目录(Print Working Directory) ls:列出文件和目录(List) - Ubuntu的清单默认有颜色区分:蓝色(目录).浅蓝色(链接文件).绿色(可执行文件) ...
- CSS3 transform封装
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- CSS3-------弹簧特效
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- unityshader(属性)
_Color("Color",Color)=(1,1,1,1)//RGBA _Vector("vector",Vector)=(1,2,3,4) //,fixe ...
- GC回收算法&&GC回收器
GC回收算法 什么是垃圾? 类比日常生活中,如果一个东西经常没被使用,那么就可以说是垃圾. 同理,如果一个对象不可能再被引用,那么这个对象就是垃圾,应该被回收. 垃圾:不可能再被引用的对象. fina ...