当我们在写一个页面,内容过多时我们需要滚动页面来查看,但是注意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水平滚动的更多相关文章

  1. scrollIntoView 前的元素滚动到浏览器窗口的可视区域内 不止垂直滚动,还有水平滚动

    Element.scrollIntoView() 方法让当前的元素滚动到浏览器窗口的可视区域内 element.scrollIntoView(); // 等同于element.scrollIntoVi ...

  2. Android学习笔记技巧之垂直和水平滚动视图

    <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android=" ...

  3. ScrollView垂直滚动控件

    ScrollView垂直滚动控件 一.简介 二.方法 1)ScrollView垂直滚动控件使用方法 1.在layout布局文件的最外层建立一个ScrollView控件 2.在ScrollView控件中 ...

  4. [转]HorizontalScrollView介绍--支持水平滚动的android布局容器

    类概述 用 于布局的容器,可以放置让用户使用滚动条查看的视图层次结构,允许视图结构比手机的屏幕大.HorizontalScrollView是一种 FrameLayout(框架布局),其子项被滚动查看时 ...

  5. HorizontalScrollView水平滚动控件

    HorizontalScrollView水平滚动控件 一.简介 用法ScrollView大致相同 二.方法 1)HorizontalScrollView水平滚动控件使用方法 1.在layout布局文件 ...

  6. IOS UIScrollView + UIButton 实现segemet页面和顶部标签页水平滚动效果

    很长一段时间没有写博客了,最近在学习iOS开发,看了不少的代码,自己用UIScrollView和UIButton实现了水平滚动的效果,有点类似于今日头条的主界面框架,效果如下: 代码如下: MyScr ...

  7. Android中如何实现多行、水平滚动的分页的Gridview?

    功能要求: (1)比如每页显示2X2,总共2XN,每个item显示图片+文字(点击有链接). 如果单行水平滚动,可以用Horizontalscrollview实现. 如果是多行水平滚动,则结合Grid ...

  8. [iOS] UICollectionView实现图片水平滚动

    最新更新: 简单封装了一下代码,参考新文章:UICollectionView实现图片水平滚动 先简单看一下效果: 新博客:http://wossoneri.github.io 准备数据 首先先加入一些 ...

  9. ASP.NET中使用JavaScript实现图片自动水平滚动效果

    参照网上的资料,在ASP.NET中使用JavaScript实现图片自动水平滚动效果. 1.页面前台代码: <%@ Page Language="C#" AutoEventWi ...

随机推荐

  1. shell循环ping ip的写法

    #!/bin/bash for i in `seq 1 20` do if ping -w 2 -c 1 192.168.43.$i | grep "100%" > /dev ...

  2. docker常用命令、镜像命令、容器命令、数据卷,使用dockerFile创建镜像,dockefile的语法规则。

    一.docker常用命令? 1. 常用帮助命令 1.1 docker的信息以及版本号 /* docker info 查看docker的信息 images2 docker本身就是一个镜像. docker ...

  3. 布客&#183;ApacheCN 编程/大数据/数据科学/人工智能学习资源 2020.2

    特约赞助商 公告 我们愿意普及区块链技术,但前提是互利互惠.我们有大量技术类学习资源,也有大量的人需要这些资源.如果能借助区块链技术存储和分发,我们就能将它们普及给我们的受众. 我们正在招募项目负责人 ...

  4. JVM学习十四 - (复习)类文件结构

    类文件结构 JVM 的"无关性" 谈论 JVM 的无关性,主要有以下两个: 平台无关性:任何操作系统都能运行 Java 代码 语言无关性: JVM 能运行除 Java 以外的其他代 ...

  5. 分布式系统及CAP理论

    一.集中式系统 在学习分布式之前,先了解一下与之相对应的集中式系统是什么样的. 集中式系统用一句话概括就是:一个主机带多个终端.终端没有数据处理能力,仅负责数据的录入和输出.而运算.存储等全部在主机上 ...

  6. IAAS, SAAS, PAAS

    原文是Pizza‐as‐a‐Service: a detailed view,用来类比Cloud Service Models.出处来自于Data Sovereignty and the Cloud ...

  7. C语言之清空缓存区

    感谢大佬:https://blog.csdn.net/qq_26768741/article/details/50933598 在C语言中,我们常常需要去清空缓存区,对于缓存区清空的重要性,接下来我们 ...

  8. tomcat访问所有的资源,都是用Servlet来实现的

    感谢大佬:https://www.zhihu.com/question/57400909 tomcat访问所有的资源,都是用Servlet来实现的. 在Tomcat看来,资源分3种 静态资源,如css ...

  9. _call妙用

    class Magic { function __call($name,$arguments) { if($name=='foo') { if(is_int($arguments[0])) $this ...

  10. 计算机网络再次整理————tcp周边[八]

    前言 tcp的包的格式可以看我以前的计算机网络整理,下面这些周边只是为了开发时候我们能用到一些理论知识. 正文 首先要介绍的就是域名,为啥有域名这东西呢?单纯站在网络的角度上讲这属于应用层的东西了. ...