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 ...
随机推荐
- linux中awk命令(最全面秒懂)
目录 一:linux中awk命令 1.awk命令简介 2.awk作用 3.awk的语法格式 4.解析awk使用方法 5.参数 6.awk的生命周期 二:awk中的预定义变量 三:awk运行处理规则的执 ...
- Redis命令大全(超详细)
一:序 其实本文的命令大家都可以去官网学习,但是我出这篇文章只是以更直观的方式来解读官网上的命令,让大家一眼可以看得懂,看的明白: 注意:我全文使用的Redis版本为 6.2.x 版本,低版本可能有些 ...
- IDE添加自定义注释
前言:最近在找IDE自定义模板注释时,十分不愉快,找了很久,才找到适合自己的,故记录一下 一.IDE自定义类注释: 1:打开自定义模板界面,并添加自定义内容: 2:新建类,效果如下 备注: ...
- IntelliJ IDEA 官方网站 http://www.jetbrains.com/idea/
IntelliJ IDEA 官方网站 http://www.jetbrains.com/idea/
- Android 关于Intent的一些简略总结
感谢大佬:https://www.jianshu.com/p/19147a69e970 Intent 常用构造方法: | 方法 | 描述 | |Intent() | 构造一个空 Intent | | ...
- linux上printf出带颜色字体
转载请注明来源:https://www.cnblogs.com/hookjc/ 统一定义: #define NONE "\033[m" #define RED ...
- JS实现new关键字的功能
一.前言 众所周知:没有对象怎么办?那就new一个! 那么在JS中,当我们new一个对象的时候,这个new关键字内部都干了什么呢? 现在我们就来剖析一下原生JS中new关键字内部的工作原理. 二.原始 ...
- Maven多环境配置实战 filter
目前在开发一个wap项目,主要有开发.测试和最终部署上线几个阶段,每个阶段对配置(数据库.日志)都有不同的设置.以前都是以开发环境为主,在测试和部署上线时由部署工程师负责修改配置并上线.但是公司并非都 ...
- SpringCloud微服务实战——搭建企业级开发框架(三十六):使用Spring Cloud Stream实现可灵活配置消息中间件的功能
在以往消息队列的使用中,我们通常使用集成消息中间件开源包来实现对应功能,而消息中间件的实现又有多种,比如目前比较主流的ActiveMQ.RocketMQ.RabbitMQ.Kafka,Stream ...
- 「Python实用秘技05」在Python中妙用短路机制
本文完整示例代码及文件已上传至我的Github仓库https://github.com/CNFeffery/PythonPracticalSkills 这是我的系列文章「Python实用秘技」的第5期 ...