高仿快递100--实战之RadioGroup和RadioButton应用
来源:互联网 发布:昆明行知中学宿舍 编辑:程序博客网 时间:2024/05/16 11:17
1.RadioButton和CheckBox的区别:
从xml布局文件中,看出使用了radiogroup,并且包含了四个radiobutton。这样便可以实现出那个弹出的popUpWindow.并且在RadioButton的图片中使用了状态选择器,分别在按下 选中和正常状态下,显示三种不同色值得图片,以一个为例,如下:java代码如下,代码里都有注释,目测可以看明白:
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 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 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>
- /**
- * 显示签收状态的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的应用也不少,大同小异,关于这个小知识点就介绍到这了。
0 0
- 高仿快递100--实战之RadioGroup和RadioButton应用
- 高仿快递100--实战之RadioGroup和RadioButton应用
- Android UI学习之RadioButton和RadioGroup
- Android按钮控件之RadioGroup和RadioButton
- Android控件之RadioGroup和RadioButton
- Widgets之RadioButton、RadioGroup和CheckBox
- Android控件之RadioButton和RadioGroup
- Android RadioGroup 之 RadioBUtton
- RadioGroup和RadioButton
- RadioGroup和RadioButton
- RadioGroup和RadioButton
- RadioGroup和RadioButton
- 使用RadioButton 和RadioGroup
- RadioGroup和Radiobutton
- Android RadioGroup和RadioButton
- RadioGroup和RadioButton
- RadioGroup和RadioButton
- Android常见控件之RadioGroup,RadioButton,CheckBox和Toast
- 存折更换后原存折号是否存在
- OVS+KVM 虚拟环境测试
- 书本第七单元(212)实验2
- 视频免费去除广告神器,天行广告防火墙:广告防火墙
- 【BZOJ 4070】 [Apio2015]雅加达的摩天楼
- 高仿快递100--实战之RadioGroup和RadioButton应用
- SSH based on Web Technology
- linux链接命令
- 文章标题CSDN学院的所有付费课程仅支持C币支付。
- ioremap
- php中header函数参数的Cache-control:private,no-cache,must-revalidate,max-age是使用方法!
- POJ 3104 Drying (二分)
- 技术揭秘12306改造(二):探讨12306两地三中心混合云架构
- [经典]Linux内核中ioremap映射的透彻理解