Android中使用HorizontalScrollView横向滑动布局
来源:互联网 发布:手机淘宝怎么发布宝贝 编辑:程序博客网 时间:2024/05/22 09:44
在Android中,ListView通常用来实现纵向滚动的列表,而HorizontalScrollView则可以实现横向滚动的列表项。
引入HorizontalScrollView控件很简单,例如在一个LinearLayout中:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <HorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> </HorizontalScrollView></LinearLayout>
这时我们没有添加任何子控件,因此IDE提示我们“This HorizontalScrollView view is useless (no children, no background, no id, no style)”
作为示例,我们尝试在这个HorizontalScrollView中添加若干个按钮:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.viewholdertest.MainActivity" > <HorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello"/> ......(余下的省略) </HorizontalScrollView></LinearLayout>
这时IDE会提示我们:“A scroll view can have only one child”。
原来,在HorizontalScrollView中,只可存在一个直接的子View。因此正确的用法是使用一个如LinearLayout这样的控件,将多个子View放入其中,改好的布局文件是这样的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.viewholdertest.MainActivity" > <HorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello" /> ......(余下的省略) </LinearLayout> </HorizontalScrollView></LinearLayout>
注意HorizontalScrollView中LinearLayout的witdh属性应为”wrap_content”。
现在运行APP,便可以通过横向滑动,将多余的按钮显示出来了。
1 0
- Android中使用HorizontalScrollView横向滑动布局
- android 横向滑动 HorizontalScrollView
- Android中抽屉实现,HorizontalScrollView横向滑动传值后获取数据
- Android 自定义 HorizontalScrollView 横向滑动效果
- 使用HorizontalScrollView 实现ListView横向滑动
- 使用HorizontalScrollView实现横向滑动广告栏
- 横向滑动HorizontalScrollView+Gridview
- HorizontalScrollView横向滑动
- HorizontalScrollView横向滑动
- HorizontalScrollView 横向滑动菜单
- android中scrollview嵌套HorizontalScrollView导致横向滑动卡顿现象解决
- android中scrollview嵌套HorizontalScrollView导致横向滑动卡顿现象解决
- android中scrollview嵌套HorizontalScrollView导致横向滑动卡顿现象解决
- android中scrollview嵌套HorizontalScrollView导致横向滑动卡顿现象解决
- 【CustomScrollView】 Android中ScrollView嵌套HorizontalScrollView导致横向滑动卡顿现象解决
- android 横向可滑动布局
- 横向滑动菜单, HorizontalScrollView,fragment,Viewpager结合使用
- Android_横向滑动菜单, HorizontalScrollView,Fragment,Viewpager结合使用
- C++ Primer Plus第六版 第十四章 编程练习答案
- 实现第三方实时对客户银行代理专用账户进行认证的装
- 如何为Eclipse/ADT 安装Eclipse Marketplace插件
- gradle学习笔记
- 反转数组
- Android中使用HorizontalScrollView横向滑动布局
- Android自定义View的实现总结
- OpenJudge_P2728 摘花生(DP)
- css3和html5的基础
- Single Number III
- MCMC与Gibbs Sampling
- Java多线程
- 黑马程序员——Foundation框架——常用结构体
- 二叉树的的所有操作——转化为静态二叉链表,求深度,求先序排列,求中序排列,求后序排列,求层次遍历,求度为0.1.2的节点个数