当我们在写一个页面,内容过多时我们需要滚动页面来查看,但是注意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. UncLutter

    在 Mac 上「速记」的正确姿势:Unclutter 现代人的大脑,每天都会被大量有用,或无用的东西充斥着,过多「思想垃圾」的沉重负担就容易导致失忆.也就是说,你很可能会记得一个无关紧要,但给你留下深 ...

  2. ansible roles实践——安装java

    [root@master] /etc/ansible$ cat roles/java/tasks/main.yml ---- name: unzip jdk unarchive: src=jdk-8u ...

  3. 磁盘sda,hda,sda1,并行,串行

    1.sd,hd表示硬盘, a表示第一块盘, 1表示硬盘上的第一个分区 2.sd是Serial ATA Disk ,表示硬盘是scsi,SATA串行接口 hd是 hard disk,表示硬盘是IDE(也 ...

  4. 微服务架构 | 4.2 基于 Feign 与 OpenFeign 的服务接口调用

    目录 前言 1. OpenFeign 基本知识 1.1 Feign 是什么 1.2 Feign 的出现解决了什么问题 1.3 Feign 与 OpenFeign 的区别与对比 2. 在服务消费者端开启 ...

  5. 带你十天轻松搞定 Go 微服务系列(八、服务监控)

    序言 我们通过一个系列文章跟大家详细展示一个 go-zero 微服务示例,整个系列分十篇文章,目录结构如下: 环境搭建 服务拆分 用户服务 产品服务 订单服务 支付服务 RPC 服务 Auth 验证 ...

  6. Jvm内存回收

    一.什么内存会被回收 可达性分析算法 通过一系列的GC ROOT的对象作为超始点,从这些节点开始向下搜索,搜索所走的路径称为"引用链",当一个对象到GC ROOT之间没有任何引用链 ...

  7. 010 Linux 文本统计与去重 (wc 和 uniq)

    wc 命令一般是作为组合命令的一员与其他命令一同起到统计的作用.而一般情况下使用wc -l 命令较多. uniq 可检查文本文件中重复出现的行,一般与 sort 命令结合使用.一起组合搭配使用完成统计 ...

  8. background-position:color url(image) -left -up no-repeat;

    转载请注明来源:https://www.cnblogs.com/hookjc/ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transit ...

  9. 在CentOS 6.x/7.x上安装git

    方式一.yum安装 # yum info git Failed to set locale, defaulting to C Loaded plugins: fastestmirror Loading ...

  10. rabbitMq使用guest登录不上的问题总结

    自己mac电脑上的mq在电脑关机(直接按电源键关机),在开机后,rabbitMq连不上了,报500错误. 1.在使用brew uninstall rabbitmq --force后; 2.我手动安装了 ...