Android RadioGroup中横向、竖向布局RadioButton的问题
来源:互联网 发布:漫步者ma3网络重置 编辑:程序博客网 时间:2024/06/07 05:45
转载:http://blog.csdn.net/aminfo/article/details/7558308
RadioGroup默认的横向android:orientation="horizontal"、竖向布局android:orientation="vertical",无法设置每行显示的个数,只能全部横向显示或者竖向显示。
而通过线性布局模版后,RadioButton却变成不是同一个组的,变成不是单选的,达不到原先想要的效果。
本例中是想在RadioGroup中一行显示2个RadioButton,上面的方法行不通,后来发现在RadioButton用android:layout_marginLeft和android:layout_marginTop可能设置RadioButton的相对位置,于是,通过下面代码,实现了一行显示2列RadioButton,目前还未测试在不同分辨率下是否会出现误差。效果图如下:
布局代码如下:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/layout_sort"
- android:layout_width="fill_parent"
- android:layout_height="120px"
- android:layout_weight="1"
- android:orientation="vertical"
- android:layout_gravity="center"
- android:gravity="center"
- android:layout_margin="5px"
- android:paddingLeft="10px"
- android:paddingRight="10px"
- android:paddingTop="5px"
- android:paddingBottom="5px">
- <ScrollView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:scrollbars="vertical"
- android:fadingEdge="vertical">
- <LinearLayout android:id="@+id/layout_sort0"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
- <LinearLayout android:id="@+id/layout_sort1"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:layout_gravity="left"
- android:gravity="left">
- <TextView android:id="@+id/rename_sortTitle"
- android:layout_width="fill_parent"
- android:layout_height="32px"
- android:singleLine="true"
- android:textSize="20sp"
- android:textStyle="bold"
- android:gravity="center_vertical|left"
- android:layout_gravity="center_vertical|left"
- android:text="请选择排序方式:" />
- <RadioGroup android:id="@+id/orderBy"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
- <RadioButton android:id="@+id/orderBy1"
- android:text="名称"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
- <RadioButton android:id="@+id/orderBy2"
- android:text="日期"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="120px"
- android:layout_marginTop="-48px"/>
- <RadioButton android:id="@+id/orderBy3"
- android:text="类型"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
- <RadioButton android:id="@+id/orderBy4"
- android:text="大小"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="120px"
- android:layout_marginTop="-48px" />
- <RadioButton android:id="@+id/orderBy5"
- android:text="系统默认"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
- </RadioGroup>
- <View android:layout_width="fill_parent"
- android:layout_height="1dip"
- android:background="#ff666666" />
- <RadioGroup android:id="@+id/orderLx"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <RadioButton android:id="@+id/orderLx1"
- android:text="升序"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
- <RadioButton android:id="@+id/orderLx2"
- android:text="降序"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="120px"
- android:layout_marginTop="-48px" />
- </RadioGroup>
- </LinearLayout>
- <LinearLayout android:id="@+id/layout_sort2"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:layout_gravity="center"
- android:gravity="center">
- <Button android:id="@+id/sortOk"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="确定"
- android:layout_margin="5px"/>
- <Button android:id="@+id/sortCancel"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="取消"
- android:layout_margin="5px"/>
- </LinearLayout>
- </LinearLayout>
- </ScrollView>
- </LinearLayout>
通过修改 RadioButton的android:layout_marginLeft和android:layout_marginTop属性实现
0 0
- Android RadioGroup中横向、竖向布局RadioButton的问题
- Android RadioGroup中横向、竖向布局RadioButton的问题
- Android布局中有两个RadioGroup的RadioButton选中问题
- Android中RadioGroup和RadioButton布局实例
- 可以解决RadioGroup中两个RadioButton选中以及RadioButton回行布局的RadioGroup
- 动态布局中RadioGroup的RadioButton有时候不互斥的原因
- 日积月累:在RadioGroup中实现RadioButton的线性布局
- 在RadioGroup中实现RadioButton的线性布局
- 在RadioGroup中实现RadioButton的多行多列线性布局
- Android开发—RadioGroup中RadioButton默认选中问题
- Android ListView中的项中包含RadioGroup时,RadioButton混乱选中的问题的解决方法
- Android RadioGroup中设置默认选中RadioButton 后,选中两个的问题 解决方法
- Android RadioGroup中设置默认选中RadioButton 后,选中两个的问题 解决方法
- Android 横向竖向的抽屉菜单
- 【android】RadioGroup+RadioButton+HorizontalScrollview实现顶部横向菜单栏
- 关于RadioGroup中RadioButton不居中的问题
- Dialog中存在radiogroup动态添加radiobutton的ID问题
- RadioGroup布局RadioButton
- hibernate的get、load区别
- Android L中水波纹点击效果的实现
- spring整合redis做缓存实例
- Android内存分析和调优
- Cocos2d-x 屏幕适配解决方案
- Android RadioGroup中横向、竖向布局RadioButton的问题
- ubuntu14.04-开机引导_开机项设置
- unsigned char和signed char型变量的区别,赋值后它在内存中的存储形式
- on duplicate key update简单使用
- STM32 USB-HID通信移植步骤
- 嵌入式linux入门之shell中read的选项及用法
- Maven项目的创建
- Abbott的复仇——最短路
- PMP学习有感