博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
高仿快递100--实战之RadioGroup和RadioButton应用
阅读量:6977 次
发布时间:2019-06-27

本文共 4382 字,大约阅读时间需要 14 分钟。

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.简介完后,先来看一下本应用中的效果图吧:

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

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

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

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的应用也不少,大同小异,关于这个小知识点就介绍到这了。

你可能感兴趣的文章
集群概述及原理笔记(1)
查看>>
主动防病毒内容篇
查看>>
无准备,不编程——计算机达人成长之路(15)连载
查看>>
服务器监控--cacti中英文版安装全解
查看>>
Nginx+Tomcat实现反向代理与动静分离
查看>>
WSUS Troubleshooting guide
查看>>
在SQL中使用CRL函数示例
查看>>
ATLAS入门篇之CascadingDropDown控件编程
查看>>
《从零开始学Swift》学习笔记(Day 47)——final关键字
查看>>
linux下磁盘镜像软件DRBD的使用
查看>>
snort源码的详细分析
查看>>
揭开Annotation的面纱
查看>>
使用DPM2007备份还原Exchange2007邮箱数据库
查看>>
zabbix企业应用之监控oracle
查看>>
FOSCommentBundle功能包:设置Doctrine ODM映射
查看>>
[Web 开发] 定制IE下载对话框的按钮(打开/保存)
查看>>
无法访问D盘,执行页内操作时的错误
查看>>
我的家庭私有云计划-13
查看>>
转载:什么才是程序员的核心竞争力
查看>>
android:关于主工程和library project
查看>>