当我们在写一个页面,内容过多时我们需要滚动页面来查看,但是注意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. AOP操作-AspectJ配置文件

    AOP操作(AspectJ配置文件)(了解) (实际中大部分用注解方式) 1,创建两个类,增强类和被增强类,创建方法 2,在spring配置文件中创建两个类对象 3,在spring配置文件中配置切入点

  2. 负载均衡的比例(权重,ip_hash,轮询)

    目录 一:负载均衡的比例 1.轮询 2.权重 3.ip_hash 二:测试轮询 1.测试 2.重启 3.网址测试 三:测试ip_hash 一:负载均衡的比例 1.轮询 # 默认情况下,Nginx负载均 ...

  3. nginx二进制安装

    目录 一:二进制安装nginx 1.下载CentOS源 2.安装CentOS源 3.下载epel源(失败显示未找到命令) 4.解决依赖 5.安装Epel源 6.安装nginx 一:二进制安装nginx ...

  4. resp.getWriter().print(categoryList)、resp.getWriter().write(String)与new ObjectMapper().writeValue(resp.getOutputStream(),categoryList)的区别

    前言:最近在复习原生的servlet的时候,对其输出流不理解,故总结一下: resp.getWriter().print(categoryList) 可以输出字符串,也可以输出对象,可能还有其他类型, ...

  5. Linux中3个文件查找相关命令详解

    源于:https://mp.weixin.qq.com/s/VPs-IXY6RoxbltHIxtIbng which命令 我们经常在linux要查找某个文件,但不知道放在哪里了,可以使用下面的一些命令 ...

  6. CSS网页使用Font Awesome图标字体时,css定义 content 属性

    原文地址: http://blog.csdn.net/laurel_y/article/details/70842157

  7. 使用Reachability监测网络变化-陈鹏

    在appdelegate里面添加观察者,并启动监测 // 使用通知中心监听kReachabilityChangedNotification通知 [[NSNotificationCenter defau ...

  8. DatabaseMetaData

    getColumns public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern ...

  9. 有手就行3——持续集成环境—maven、tomcat、安装和配置

    有手就行3--持续集成环境-maven.tomcat.安装 持续集成环境(5)-Maven安装和配置 持续集成环境(6)-Tomcat安装和配置 持续集成环境(5)-Maven安装和配置 在Jenki ...

  10. ELK 日志分析系统概述及部署

    ELK 日志分析系统概述及部署 1.ELK概述: ELK简介 : ELK平台是一套完整的日志集中处理解决方案,将 ElasticSearch.Logstash 和 Kiabana 三个开源工具配合使用 ...