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 ...
随机推荐
- 谈谈你对java平台的理解?
问题:谈谈你对java平台的理解?java是解释执行,这句话对吗? 典型回答:java本身是一种面向对象的语言,具有很好的跨平台的能力,能够做到“write once ,run anywhere”.另 ...
- .Net Mvc过滤器观察者模式记录网站报错信息
基本介绍: 观察者模式是一种对象行为模式.它定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新.在观察者模式中,主题是通知的发布者,它发出通知时并不 ...
- 基于Spring Boot自建分布式基础应用
目前刚入职了一家公司,要求替换当前系统(单体应用)以满足每日十万单量和一定系统用户负载以及保证开发质量和效率.由我来设计一套基础架构和建设基础开发测试运维环境,github地址. 出于本公司开发现状及 ...
- idea 2019安装完(打不开&&启动不了)问题解决(最全解决方法)
今天从网盘把idea下载下来后一路安装,准备 设置的时候不管怎么打开 他都无动于衷没办法,卸了安,安了卸,反复折腾了 好几遍 它都无动于衷.于是开始在百度上找答案看了 好几个 方法一遍一遍试还是不行, ...
- DRF (Django REST framework) 中的视图扩展类
2. 五个扩展类 1)ListModelMixin 列表视图扩展类,提供list(request, *args, **kwargs)方法快速实现列表视图,返回200状态码. 该Mixin的list方法 ...
- 一文了解Python常见的序列化操作
关于我 一个有思想的程序猿,终身学习实践者,目前在一个创业团队任team lead,技术栈涉及Android.Python.Java和Go,这个也是我们团队的主要技术栈. Github:https:/ ...
- Vue中 父子传值 数据丢失问题
在Vue中,父子组件传值,子组件通过props接收父组件传递的数据 父组件 questionList : 传递数据参数 questionsLists: 传递数据源 子组件 porps 接收父组件方式 ...
- 第一个基于ArcGIS的Android应用
使用Android Studio创建第一个工程 打开Android Studio,新建工程.在Application name处填写项目名称,company domain是公司地址,将来作为包名,点 ...
- Integer 使用==判断127和超过128的数据的区别
Integer封装类型字数据当超过一定长度后,若使用==来判断数否相等,那么判断的结果是false; Integer的范围是超过128就是false. 对于所有封装类而言,建议使用equals来进行判 ...
- python学习——python之禅
(一)python之禅: 在python中运行import this你会看到这样一段文字: The Zen of Python, by Tim Peters Beautiful is better ...