用ScrollView实现RadioGroup的滚动
来源:互联网 发布:php 围棋提子 编辑:程序博客网 时间:2024/06/07 12:05
最近在制作一个app,其中一个活动使用了RadioGroup控件,该控件包含了几十个RadioButton供用户选择,这么多的RadioButton无法显示在一个页面内,大多数超出了页面的范围,需要滚动显示。刚开始时,只是把RadioGroup控件放在了linearlayout布局内,但是这种情况下无法滚动显示。后来我把linearlayout放在一个ScrollView控件内,所有的RadioButton就可以滚动显示了。如下所示:
<?xml version="1.0" encoding="utf-8"?><ScrollView xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:fillViewport="false"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent" ><RadioGroupandroid:id="@+id/radioGroup1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentRight="true"android:layout_alignParentTop="true"android:layout_marginLeft="80dp"><RadioButtonandroid:id="@+id/radio1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="15dp"android:checked="true"android:text="1" /><RadioButtonandroid:id="@+id/radio2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="15dp"android:text="2" /><RadioButtonandroid:id="@+id/radio3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="15dp"android:text="3" />
…
</RadioGroup></LinearLayout></ScrollView>
事实上,ScrollView是一个FrameLayout,因此,它里面只能放一个子女,最经常放的就是一个linearlayout。把需要滚动显示的内容放到该linearlayout中即可。
可以参考下面关于ScrollView的基本描述:
Layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display. A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through.
- 用ScrollView实现RadioGroup的滚动
- 用3个label实现scrollView的循环滚动效果
- 用纯代码实现RadioGroup,并且实现滚动条
- 用纯代码实现RadioGroup,并且实现滚动条
- ScrollView实现TextView一行一行的滚动效果
- iOS中scrollview自动滚动的实现
- iOS中scrollview自动滚动的实现
- iOS中scrollview自动滚动的实现
- iOS中scrollview自动滚动的实现
- Android 实现无限滚动的ScrollView
- 重写ScrollView实现两个ScrollView的同步滚动显示
- 重写ScrollView实现两个ScrollView的同步滚动显示
- 重写ScrollView实现两个ScrollView的同步滚动显示
- 重写ScrollView实现两个ScrollView的同步滚动显示
- ScrollView实现滚动
- ScrollView实现滚动效果
- ScrollView自动滚动实现
- ScrollView实现滚动效果
- c++ 之详述继承篇
- [BZOJ2986]Non-Squarefree Numbers(二分+容斥原理)
- oracle数据库sql基础
- Douglas-Peucker算法理解
- UITableView优化技巧
- 用ScrollView实现RadioGroup的滚动
- EffectiveJava第五章:泛型
- Azure--本机PC如何将文件上传至云端的虚拟机
- TestNG和Junit的区别
- Python的zip函数
- 详谈 JavaScript 数组去重 1 :实现篇
- QT 生成二维码接口封装
- How to Build ARPACK in Windows10 with Microsoft Visual Studio 2015
- 快速学会制作表格