1.RadioButton和CheckBox的差别:

a.单个RadioButton在选中后,通过点击无法变为未选中

单个CheckBox在选中后。通过点击能够变为未选中

b.一组RadioButton。仅仅能同一时候选中一个

一组CheckBox,能同一时候选中多个

c.RadioButton在大部分UI框架中默认都以圆形表示

CheckBox在大部分UI框架中默认都以矩形表示

2.RadioButton和RadioGroup的关系:

a.RadioButton表示单个圆形单选框。而RadioGroup是能够容纳多个RadioButton的容器

b.每一个RadioGroup中的RadioButton同一时候仅仅能有一个被选中

c.不同的RadioGroup中的RadioButton互不相干,即假设组A中有一个选中了,组B中依旧能够有一个被选中

d.大部分场合下,一个RadioGroup中至少有2个RadioButton

e.大部分场合下,一个RadioGroup中的RadioButton默认会有一个被选中。并建议您将它放在RadioGroup中的起始位置

3.简介完后,先来看一下本应用中的效果图吧:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDM1ODE2OA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

简单的一个弹出pop,然后里面提供了四种订单的状态,实现起来也不难,闲来看一下xml代码吧:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/rl_order_parent"
android:orientation="vertical" > <RelativeLayout
android:id="@id/top_arrow"
android:layout_width="fill_parent"
android:layout_height="@dimen/height_title_bar" > <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="@drawable/btn_sort_arrow" />
</RelativeLayout> <RadioGroup
android:id="@+id/btn_sort"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/top_arrow"
android:background="@drawable/btn_sort_bg"
android:checkedButton="@id/btn_sort_unsigned"
android:gravity="center"
android:orientation="horizontal"
android:padding="10.0dip" > <RadioButton
android:id="@+id/btn_sort_all"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:background="#00000000"
android:button="@null"
android:clickable="true"
android:drawableTop="@drawable/btn_sort_all_selector"
android:gravity="center"
android:scaleType="matrix"
android:text="@string/btn_sort_all"
android:textColor="@color/grey_878787" /> <RadioButton
android:id="@+id/btn_sort_unsigned"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:background="#00000000"
android:button="@null"
android:clickable="true"
android:drawableTop="@drawable/btn_sort_unsigned_selector"
android:gravity="center"
android:scaleType="matrix"
android:text="@string/btn_sort_unsigned"
android:textColor="@color/blue_kuaidi100" /> <RadioButton
android:id="@+id/btn_sort_signed"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:background="#00000000"
android:button="@null"
android:clickable="true"
android:drawableTop="@drawable/btn_sort_signed_selector"
android:gravity="center"
android:scaleType="matrix"
android:text="@string/btn_sort_signed"
android:textColor="@color/grey_878787" /> <RadioButton
android:id="@+id/btn_sort_recycle"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:background="#00000000"
android:button="@null"
android:clickable="true"
android:drawableTop="@drawable/btn_sort_recycle_selector"
android:gravity="center"
android:scaleType="matrix"
android:text="@string/btn_sort_recycle"
android:textColor="@color/grey_878787" />
</RadioGroup> <View
android:id="@+id/btn_grey_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/btn_sort"
android:background="@color/black_7000" /> </RelativeLayout>

从xml布局文件里,看出使用了radiogroup,而且包括了四个radiobutton。

这样便能够实现出那个弹出的popUpWindow.而且在RadioButton的图片中使用了状态选择器,分别在按下 选中和正常状态下,显示三种不同色值得图片,以一个为例。例如以下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/btn_sort_signed_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/btn_sort_signed_selected" android:state_checked="true"/>
<item android:drawable="@drawable/btn_sort_signed_normal"/> </selector>

java代码例如以下,代码里都有凝视。目測能够看明确:

/**
* 显示签收状态的pop
*/
private void showOrderStatusPop() {
if (orderStatusPopView == null) {
orderStatusPopView = View.inflate(mContext, R.layout.pop_bill_sort,
null);
}
initOrderStatusPopView();
setCurrentCheckedItem();
setOrderStatusPopViewListener();
if (orderStatusPopupWindow == null) {
orderStatusPopupWindow = new PopupWindow(orderStatusPopView,
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
// 使其不聚集
orderStatusPopupWindow.setFocusable(false);
// 设置同意在外点击消失
orderStatusPopupWindow.setOutsideTouchable(true);
// 这个是为了点击“返回Back”也能使其消失,而且并不会影响你的背景
orderStatusPopupWindow.setBackgroundDrawable(new BitmapDrawable());
}
int i = DensityUtil.dip2px(mContext, 60.0f);
iv_arrow.setImageResource(R.drawable.arrow_up_float);
orderStatusPopupWindow.showAsDropDown(top, 0, -i);
} /**
* 初始化订单状态控件
*/
private void initOrderStatusPopView() {
rl_order_parent = (RelativeLayout) orderStatusPopView
.findViewById(R.id.rl_order_parent);
btn_sort = (RadioGroup) orderStatusPopView.findViewById(R.id.btn_sort);
btn_sort_all = (RadioButton) orderStatusPopView
.findViewById(R.id.btn_sort_all);
btn_sort_unsigned = (RadioButton) orderStatusPopView
.findViewById(R.id.btn_sort_unsigned);
btn_sort_signed = (RadioButton) orderStatusPopView
.findViewById(R.id.btn_sort_signed);
btn_sort_recycle = (RadioButton) orderStatusPopView
.findViewById(R.id.btn_sort_recycle); } /**
* 设置订单状态的监听
*/
private void setOrderStatusPopViewListener() {
rl_order_parent.setOnClickListener(this);
btn_sort_all.setOnClickListener(this);
btn_sort_unsigned.setOnClickListener(this);
btn_sort_signed.setOnClickListener(this);
btn_sort_recycle.setOnClickListener(this);
//给radioGroup设置选中变化的监听。便于检測当前选中了哪个,方便下次再次显示回显
btn_sort.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.btn_sort_all:
currentCheckedId = checkedId;
break;
case R.id.btn_sort_unsigned:
currentCheckedId = checkedId;
break;
case R.id.btn_sort_signed:
currentCheckedId = checkedId;
break;
case R.id.btn_sort_recycle:
currentCheckedId = checkedId;
break;
} }
});
btn_sort.check(currentCheckedId);
} /**
* 设置当前显示的状态
*/
private void setCurrentCheckedItem() {
switch (currentCheckedId) {
case R.id.btn_sort_all:
resetTextColor();
btn_sort_all.setTextColor(mContext.getResources().getColor(
R.color.blue_kuaidi100));
break;
case R.id.btn_sort_unsigned:
resetTextColor();
btn_sort_unsigned.setTextColor(mContext.getResources().getColor(
R.color.blue_kuaidi100));
break;
case R.id.btn_sort_signed:
resetTextColor();
btn_sort_signed.setTextColor(mContext.getResources().getColor(
R.color.blue_kuaidi100));
break;
case R.id.btn_sort_recycle:
resetTextColor();
btn_sort_recycle.setTextColor(mContext.getResources().getColor(
R.color.blue_kuaidi100));
break;
} } /**
* 重置文字颜色
*/
private void resetTextColor() {
btn_sort_all.setTextColor(mContext.getResources().getColor(
R.color.grey_878787));
btn_sort_unsigned.setTextColor(mContext.getResources().getColor(
R.color.grey_878787));
btn_sort_signed.setTextColor(mContext.getResources().getColor(
R.color.grey_878787));
btn_sort_recycle.setTextColor(mContext.getResources().getColor(
R.color.grey_878787)); }

这样,便实现了一个pop的弹出和radioGroup radioButton的一个结合,事实上在实际应用中,底部使用RadioGroup的应用也不少,大同小异,关于这个小知识点就介绍到这了。

高仿快递100--实战之RadioGroup和RadioButton应用的更多相关文章

  1. Android ActionBar应用实战,高仿微信主界面的设计

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/26365683 经过前面两篇文章的学习,我想大家对ActionBar都已经有一个相对 ...

  2. 【第二版】高仿Android网易云音乐企业级项目实战课程介绍

    这是一门付费Android项目课程,我们只做付费课程:同时也感谢大家的支持. 这一节,对本课程做一个简单介绍,以及放一些项目效果图,如果想直接查看项目视频演示,可以直接在腾讯课堂查看[高仿Androi ...

  3. Android 高仿微信头像截取 打造不一样的自定义控件

    转载请表明出处:http://blog.csdn.net/lmj623565791/article/details/39761281,本文出自:[张鸿洋的博客] 1.概述 前面已经写了关于检测手势识别 ...

  4. Android -- 真正的 高仿微信 打开网页的进度条效果

    (本博客为原创,http://www.cnblogs.com/linguanh/) 目录: 一,为什么说是真正的高仿? 二,为什么要搞缓慢效果? 三,我的实现思路 四,代码,内含注释 五,使用方法与截 ...

  5. 微信小程序开发日记——高仿知乎日报(上)

    本人对知乎日报是情有独钟,看我的博客和github就知道了,写了几个不同技术类型的知乎日报APP 要做微信小程序首先要对html,css,js有一定的基础,还有对微信小程序的API也要非常熟悉 我将该 ...

  6. MySQL 系列(五) 多实例、高可用生产环境实战

    MySQL 系列(五) 多实例.高可用生产环境实战   第一篇:MySQL 系列(一) 生产标准线上环境安装配置案例及棘手问题解决 第二篇:MySQL 系列(二) 史上最屌.你不知道的数据库操作 第三 ...

  7. Android实现高仿QQ附近的人搜索展示

    本文主要实现了高仿QQ附近的人搜索展示,用到了自定义控件的方法 最终效果如下 1.下面展示列表我们可以使用ViewPager来实现(当然如果你不觉得麻烦,你也可以用HorizontalScrollVi ...

  8. iOS高仿app源码:纯代码打造高仿优质《内涵段子》

    iOS高仿app源码:纯代码打造高仿优质<内涵段子>收藏下来 字数1950 阅读4999 评论173 喜欢133 Github 地址 https://github.com/Charlesy ...

  9. 转-Fragment+ViewPager组件(高仿微信界面)

    http://www.cnblogs.com/lichenwei/p/3982302.html 什么是ViewPager? 关于ViewPager的介绍和使用,在之前我写过一篇相关的文章<安卓开 ...

随机推荐

  1. 零基础如何学习 Web 安全?(转)

    在网上看了一篇文章<零基础如何学习 Web 安全?>,虽然很多东西的都不是很懂,感觉挺好的copy过来,慢慢消化: 文章地址:https://www.zhihu.com/question/ ...

  2. Codeforces #439 Div2 E

    #439 Div2 E 题意 给出二维平面,有多个询问: 把某一区域围起来(围墙之间无交点) 移除某一区域的围墙(此时保证围墙一定存在) 选定两个位置问是否可以互相到达 分析 看起来很复杂,其实这道题 ...

  3. 使用IIFE(立即执行函数)让变量私有化

    今天去看了一个GITHUB上的开源项目,在客户端JS的脚本编写的时候,代码中多次使用了IIFE. 一开始我是懵逼的,不知道这种函数的意义何在,小菜鸟嘛. 后面我去研究了一番.发现了它的主要作用就是:让 ...

  4. [CF819B]Mister B and PR Shifts

    题意:定义一个排列$p_{1\cdots n}$的“偏移量”$D=\sum _{i=1}^n\left|p_i-i\right|$ 求它所有的轮换排列中偏移量最小的是多少,要求输出轮换序数 暴力就是求 ...

  5. 【2-SAT】Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League

    先反复地扫(不超过n次),把所有可以确定唯一取法的给确定下来. 然后对于剩下的不能确定的,跑2-SAT.输出可行解时,对于a和¬a,如果a所在的强连通分量序号在¬a之前,则取a,否则不取a.如果a和¬ ...

  6. 【小笔记】斜率优化的结论(WC)

  7. SciPy中两个模块:io 和misc

    读写.mat文件 如果你有一些数据,或者在网上下载到一些有趣的数据集,这些数据以Matlab的.mat 文件格式存储,那么可以使用scipy.io 模块进行读取. data = scipy.io.lo ...

  8. Postman Json测试接口

    当传递Json数据时: 1.必须添加http头:content-type:application/json,否则会报错(后台取不到相对应的值) 注意:如果服务端只支持UTF-8,但程序未对提交数据进行 ...

  9. oracle--v$lock type字段详解

    Name Description AD ASM Disk AU Lock AF Advisor Framework AG Analytic Workspace Generation AK GES De ...

  10. "0" 并不一定是 假 (false)

    写习惯C/C++系代码的人应该很习惯看见类似这样的代码: 1 2 3 4 5 int i = 0; ...... if(i){    //这里代码不会被执行 } 因此写习惯以后会想当然地觉得其他语言里 ...