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 ...
随机推荐
- 深入理解 linux磁盘顺序写、随机写
一.前言 ● 随机写会导致磁头不停地换道,造成效率的极大降低:顺序写磁头几乎不用换道,或者换道的时间很短 ● 本文来讨论一下两者具体的差别以及相应的内核调用 二.环境准备 组件 版本 OS Ubunt ...
- 洛谷 P2572 [SCOI2010]序列操作
题意简述 维护一个序列,支持如下操作 把[a, b]区间内的所有数全变成0 把[a, b]区间内的所有数全变成1 把[a,b]区间内所有的0变成1,所有的1变成0 询问[a, b]区间内总共有多少个1 ...
- 用友网络科技Java高级开发面试题(2019)
面试时间:2019年8月18日上午9:30 面试岗位:Java高级开发 面试形式:电话面试 这些天在boss上逛了下,看见北京Java开发工资比较诱人,便萌生了去北京的想法,做一名北漂的程序猿.约了几 ...
- Scrapy爬虫框架学习
一.Scrapy框架简介 1. 下载页面 2. 解析 3. 并发 4. 深度 二.安装 linux下安装 pip3 install scrapy windows下安装 a.pip3 install w ...
- 启xin宝app的token算法破解——frida篇(四)
前两篇文章分析该APP的抓包.的逆向: 启xin宝app的token算法破解--抓包分析篇(一) 启xin宝app的token算法破解--逆向篇(二) 启xin宝app的token算法破解--toke ...
- IntelliJ IDEA 2019 快捷键终极大全,速度收藏!
转载注明:https://blog.csdn.net/WantFlyDaCheng/article/details/100078777 自动代码 查询快捷键 其他快捷键 调试快捷键 重构 十大Inte ...
- ECMAScript---变量
上上篇我们说到ESMAScript是JS的语法规划,JS中的变量.数据类型.语法规范.操作语句.设计模型等都是ES规定的,现在咱们聊一下JS中的变量和常量 变量(variable) 它不是具体值,只是 ...
- egret之红包满屏随意飘动
在做这个需求之前,我们假设屏幕上同时飘动的红包数最大为10 ) { let redBag = GameUtil.createBitmapByName("Red_bag_png"); ...
- rocketmq 部署启动指南-Docker 版
最近学习使用 rocketmq,需要搭建 rocketmq 服务端,本文主要记录 rocketmq 搭建过程以及这个过程踩到的一些坑. 准备工作 在搭建之前,我们需要做一些准备工作,这里我们需要使用 ...
- SDU暑期集训排位(5)
SDU暑期集训排位(5) A. You're in the Army Now 题意 类似选志愿.每个人有 mark,有优先级从高到低的志愿. 做法 定睛一看,鲨鼻题.然后 WA. 为什么会 WA 呢? ...