ScrollView垂直滚动和HrizontalScrollView水平滚动
当我们在写一个页面,内容过多时我们需要滚动页面来查看,但是注意ScrollView下只能有一个元素,所以要把主页面改下,这样就只有一个LinearLayout元素:
1 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
2 xmlns:app="http://schemas.android.com/apk/res-auto"
3 xmlns:tools="http://schemas.android.com/tools"
4 android:layout_width="match_parent"
5 android:layout_height="match_parent"
6 android:orientation="vertical"
7 android:padding="20dp">
8
9 <LinearLayout
10 android:layout_width="match_parent"
11 android:layout_height="wrap_content"
12 android:orientation="vertical">
13 <Button
14 android:id="@+id/btn_textview"
15 android:layout_width="match_parent"
16 android:layout_height="wrap_content"
17 android:text="textview"
18 android:textColor="#000000"
19 android:backgroundTint="#FFFF00"
20 android:textAllCaps="false"/>
21
22 <Button
23 android:id="@+id/btn_button"
24 android:layout_width="match_parent"
25 android:layout_height="wrap_content"
26 android:text="button"
27 android:textColor="#000000"
28 android:backgroundTint="#FFFF00"
29 android:textAllCaps="false"/>
30
31 <Button
32 android:id="@+id/btn_edittext"
33 android:layout_width="match_parent"
34 android:layout_height="wrap_content"
35 android:text="edittext"
36 android:textColor="#000000"
37 android:backgroundTint="#FFFF00"
38 android:textAllCaps="false"/>
39 <!--textAllCaps是取消默认大写的设置-->
40
41 <Button
42 android:id="@+id/btn_radioButton"
43 android:layout_width="match_parent"
44 android:layout_height="wrap_content"
45 android:text="radioButton"
46 android:textColor="#000000"
47 android:backgroundTint="#FFFF00"
48 android:textAllCaps="false"/>
49
50 <Button
51 android:id="@+id/btn_checkbox"
52 android:layout_width="match_parent"
53 android:layout_height="wrap_content"
54 android:text="checkbox"
55 android:textColor="#000000"
56 android:backgroundTint="#FFFF00"
57 android:textAllCaps="false"/>
58
59 <Button
60 android:id="@+id/btn_imageview"
61 android:layout_width="match_parent"
62 android:layout_height="wrap_content"
63 android:text="imageview"
64 android:textColor="#000000"
65 android:backgroundTint="#FFFF00"
66 android:textAllCaps="false"/>
67
68 <Button
69 android:id="@+id/btn_listview"
70 android:layout_width="match_parent"
71 android:layout_height="wrap_content"
72 android:text="listview"
73 android:textColor="#000000"
74 android:backgroundTint="#FFFF00"
75 android:textAllCaps="false"/>
76
77 <Button
78 android:id="@+id/btn_gridview"
79 android:layout_width="match_parent"
80 android:layout_height="wrap_content"
81 android:text="gridview"
82 android:textColor="#000000"
83 android:backgroundTint="#FFFF00"
84 android:textAllCaps="false"/>
85
86 <Button
87 android:id="@+id/btn_scrollview"
88 android:layout_width="match_parent"
89 android:layout_height="wrap_content"
90 android:text="scrollview滚动测试"
91 android:textColor="#000000"
92 android:backgroundTint="#FFFF00"
93 android:textAllCaps="false"
94 android:layout_marginTop="300dp"/>
95 </LinearLayout>
96
97 </ScrollView>
注意LinearLayout下的height元素一定是wrap_content,不能是match_parent,否则就会出现错误,导致无法运行。
然后HrizontalScrollView水平滚动与垂直滚动同理,只能包含一个元素,最重要的是注意height和width都一定是wrap_content。可以测试一下
1 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
2 xmlns:app="http://schemas.android.com/apk/res-auto"
3 xmlns:tools="http://schemas.android.com/tools"
4 android:layout_width="match_parent"
5 android:layout_height="match_parent"
6 android:orientation="vertical"
7 android:padding="20dp">
8
9 <LinearLayout
10 android:layout_width="match_parent"
11 android:layout_height="wrap_content"
12 android:orientation="vertical">
13 <Button
14 android:id="@+id/btn_textview"
15 android:layout_width="match_parent"
16 android:layout_height="wrap_content"
17 android:text="textview"
18 android:textColor="#000000"
19 android:backgroundTint="#FFFF00"
20 android:textAllCaps="false"/>
21
22 <Button
23 android:id="@+id/btn_button"
24 android:layout_width="match_parent"
25 android:layout_height="wrap_content"
26 android:text="button"
27 android:textColor="#000000"
28 android:backgroundTint="#FFFF00"
29 android:textAllCaps="false"/>
30
31 <Button
32 android:id="@+id/btn_edittext"
33 android:layout_width="match_parent"
34 android:layout_height="wrap_content"
35 android:text="edittext"
36 android:textColor="#000000"
37 android:backgroundTint="#FFFF00"
38 android:textAllCaps="false"/>
39 <!--textAllCaps是取消默认大写的设置-->
40
41 <Button
42 android:id="@+id/btn_radioButton"
43 android:layout_width="match_parent"
44 android:layout_height="wrap_content"
45 android:text="radioButton"
46 android:textColor="#000000"
47 android:backgroundTint="#FFFF00"
48 android:textAllCaps="false"/>
49
50 <Button
51 android:id="@+id/btn_checkbox"
52 android:layout_width="match_parent"
53 android:layout_height="wrap_content"
54 android:text="checkbox"
55 android:textColor="#000000"
56 android:backgroundTint="#FFFF00"
57 android:textAllCaps="false"/>
58
59 <Button
60 android:id="@+id/btn_imageview"
61 android:layout_width="match_parent"
62 android:layout_height="wrap_content"
63 android:text="imageview"
64 android:textColor="#000000"
65 android:backgroundTint="#FFFF00"
66 android:textAllCaps="false"/>
67
68 <Button
69 android:id="@+id/btn_listview"
70 android:layout_width="match_parent"
71 android:layout_height="wrap_content"
72 android:text="listview"
73 android:textColor="#000000"
74 android:backgroundTint="#FFFF00"
75 android:textAllCaps="false"/>
76
77 <Button
78 android:id="@+id/btn_gridview"
79 android:layout_width="match_parent"
80 android:layout_height="wrap_content"
81 android:text="gridview"
82 android:textColor="#000000"
83 android:backgroundTint="#FFFF00"
84 android:textAllCaps="false"/>
85
86 <HorizontalScrollView
87 android:layout_width="wrap_content"
88 android:layout_height="wrap_content">
89 <LinearLayout
90 android:layout_width="wrap_content"
91 android:layout_height="wrap_content"
92 android:orientation="horizontal">
93 <Button
94 android:layout_width="200dp"
95 android:layout_height="300dp"
96 android:text="我只是个测试。。"
97 android:textAllCaps="false"/>
98 <Button
99 android:layout_width="200dp"
100 android:layout_height="300dp"
101 android:text="我只是个测试。。"
102 android:textAllCaps="false"/>
103 <Button
104 android:layout_width="200dp"
105 android:layout_height="300dp"
106 android:text="我只是个测试。。"
107 android:textAllCaps="false"/>
108 <Button
109 android:layout_width="200dp"
110 android:layout_height="300dp"
111 android:text="我只是个测试。。"
112 android:textAllCaps="false"/>
113 </LinearLayout>
114 </HorizontalScrollView>
115 </LinearLayout>
116
117 </ScrollView>
ScrollView垂直滚动和HrizontalScrollView水平滚动的更多相关文章
- scrollIntoView 前的元素滚动到浏览器窗口的可视区域内 不止垂直滚动,还有水平滚动
Element.scrollIntoView() 方法让当前的元素滚动到浏览器窗口的可视区域内 element.scrollIntoView(); // 等同于element.scrollIntoVi ...
- Android学习笔记技巧之垂直和水平滚动视图
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android=" ...
- ScrollView垂直滚动控件
ScrollView垂直滚动控件 一.简介 二.方法 1)ScrollView垂直滚动控件使用方法 1.在layout布局文件的最外层建立一个ScrollView控件 2.在ScrollView控件中 ...
- [转]HorizontalScrollView介绍--支持水平滚动的android布局容器
类概述 用 于布局的容器,可以放置让用户使用滚动条查看的视图层次结构,允许视图结构比手机的屏幕大.HorizontalScrollView是一种 FrameLayout(框架布局),其子项被滚动查看时 ...
- HorizontalScrollView水平滚动控件
HorizontalScrollView水平滚动控件 一.简介 用法ScrollView大致相同 二.方法 1)HorizontalScrollView水平滚动控件使用方法 1.在layout布局文件 ...
- IOS UIScrollView + UIButton 实现segemet页面和顶部标签页水平滚动效果
很长一段时间没有写博客了,最近在学习iOS开发,看了不少的代码,自己用UIScrollView和UIButton实现了水平滚动的效果,有点类似于今日头条的主界面框架,效果如下: 代码如下: MyScr ...
- Android中如何实现多行、水平滚动的分页的Gridview?
功能要求: (1)比如每页显示2X2,总共2XN,每个item显示图片+文字(点击有链接). 如果单行水平滚动,可以用Horizontalscrollview实现. 如果是多行水平滚动,则结合Grid ...
- [iOS] UICollectionView实现图片水平滚动
最新更新: 简单封装了一下代码,参考新文章:UICollectionView实现图片水平滚动 先简单看一下效果: 新博客:http://wossoneri.github.io 准备数据 首先先加入一些 ...
- ASP.NET中使用JavaScript实现图片自动水平滚动效果
参照网上的资料,在ASP.NET中使用JavaScript实现图片自动水平滚动效果. 1.页面前台代码: <%@ Page Language="C#" AutoEventWi ...
随机推荐
- Filter的生命周期及FilterConfig类介绍
Filter的生命周期包含几个方法 1,构造器方法 2,init初始化方法 第1,2步,在web工程 3,doFilter过滤方法 每次拦截到请求,就会执行 4,destroy销毁方法 停止web工程 ...
- 开源免费的WordPress个人博客主题推荐
二次元动漫类个人主题 Sakura 功能强大,美观大气,二次元动漫专属 演示地址:https://2heng.xin/theme-sakura/ 开源地址:https://github.com/mas ...
- 用 CSS 让你的文字更有文艺范
透明文字,模糊文字,镂空文字,渐变文字,图片背景文字,用 CSS 让你的文字也有 freestyle- 前言 我们做页面涉及字体的时候,最多就是换个 color 换个 font-family,总是觉得 ...
- 写react项目需要注意的
key应该是稳定的,且唯一的,尽量不要用索引作为key 都知道React组件渲染列表时需要为每个列表元素分配一个在列表中独一无二的key,key可以在DOM中的某些元素被增加或删除视乎帮助React识 ...
- C++读写图片文件
1.C方式 string sourcefilename = "D:\\Logo.jpg"; string destfilename="D:\\Logo1.jpg" ...
- CPU Cache与缓存行
编译环境:windows10+Idea+x86 CPU. 1.CPU Cache CPU 访问内存时,首先查询 cache 是否已缓存该数据.如果有,则返回数据,无需访问内存:如果不存在,则需把数据从 ...
- Lesson1——Pandas是什么
pandas目录 一.简介 Pandas 是一个开源的第三方 Python 库,从 Numpy 和 Matplotlib 的基础上构建而来,享有数据分析"三剑客之一"的盛名(Num ...
- 微服务 架构 php+go
p.p1 { margin: 0; font: 13px "Helvetica Neue"; color: rgba(0, 162, 255, 1) } 微服务 架构 php+ ...
- linux内核中的eventfd
转载请注明来源:https://www.cnblogs.com/hookjc/ eventfd 在内核版本,2.6.22以后有效.查看内核版本可以用命令 uname -r . [cpp] view p ...
- jsp include html 乱码问题
感谢大佬:https://blog.csdn.net/sessionsong/article/details/38778853 在使用<%@ include page=""% ...