Android 自学之滚动视图ScrollView

滚动视图ScrollView由FarmeLayout派生而出,他就是一个用于为普通组件添加垂直滚动条的组件;ScrollView里面最多包含一个组件,而ScrollView的作用就是为该组件添加一个垂直滚动条。(ScrollView的作用和JScrollPane非常相似,他们甚至不能被称为真正的容器。他们只是为其他的容器添加滚动条。)默认的情况下ScrollView只是为其他组件添加垂直滚动条,如果应用需要水平的滚动条,则可以借助于另一个组件:HorizontalScrollView来实现。HorizontalScrollView和ScrollView的功能基本相似,只是前者添加水平滚动条,后者添加垂直滚动条。

通过一个程序来看看HorizontalScrollView和ScrollView的应用。在ScrollView中嵌套一个HorizontalScrollView,来为应用的界面同时添加水平、垂直的滚动条

layout/main.xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <!-- 定义ScrollView,为里面的组件添加垂直滚动条 -->
 3 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
 4     android:layout_width="fill_parent"
 5     android:layout_height="fill_parent" >
 6
 7     <!-- 定义HorizontalScrollView,为里面的组件添加水平滚动条 -->
 8     <HorizontalScrollView
 9         android:layout_width="fill_parent"
10         android:layout_height="wrap_content">
11         <LinearLayout android:orientation="vertical"
12             android:layout_width="fill_parent"
13             android:layout_height="fill_parent">
14         <TextView android:layout_width="wrap_content"
15             android:layout_height="wrap_content"
16             android:text="滚动视图滚动视图滚动视图"
17             android:textSize="30dp" />
18         <TextView android:layout_width="wrap_content"
19             android:layout_height="wrap_content"
20             android:text="滚动视图滚动视图滚动视图"
21             android:textSize="30dp" />
22         <TextView android:layout_width="wrap_content"
23             android:layout_height="wrap_content"
24             android:text="滚动视图滚动视图滚动视图"
25             android:textSize="30dp" />
26         <TextView android:layout_width="wrap_content"
27             android:layout_height="wrap_content"
28             android:text="滚动视图滚动视图滚动视图"
29             android:textSize="30dp" />
30         <TextView android:layout_width="wrap_content"
31             android:layout_height="wrap_content"
32             android:text="滚动视图滚动视图滚动视图"
33             android:textSize="30dp" />
34         <TextView android:layout_width="wrap_content"
35             android:layout_height="wrap_content"
36             android:text="滚动视图滚动视图滚动视图"
37             android:textSize="30dp" />
38         <TextView android:layout_width="wrap_content"
39             android:layout_height="wrap_content"
40             android:text="滚动视图滚动视图滚动视图"
41             android:textSize="30dp" />
42         <TextView android:layout_width="wrap_content"
43             android:layout_height="wrap_content"
44             android:text="滚动视图滚动视图滚动视图"
45             android:textSize="30dp" />
46         <TextView android:layout_width="wrap_content"
47             android:layout_height="wrap_content"
48             android:text="滚动视图滚动视图滚动视图"
49             android:textSize="30dp" />
50
51         </LinearLayout>
52
53     </HorizontalScrollView>
54
55 </ScrollView>

上面界面显示和运行的效果:

Android 自学之滚动视图ScrollView

时间: 2024-08-28 02:46:35

Android 自学之滚动视图ScrollView的相关文章

Android零基础入门第61节:滚动视图ScrollView

原文:Android零基础入门第61节:滚动视图ScrollView 前面几期学习了ProgressBar系列组件.ViewAnimator系列组件.Picker系列组件和时间日期系列组件,接下来几期继续来学习常见的其他组件. 一.ScrollView概述 从前面的学习有的同学可能已经发现,当拥有很多内容时屏幕显示不完,显示不全的部分完全看不见.但是在实际项目里面,很多内容都不止一个屏幕宽度或高度,那怎么办呢?那就需要本节学习的ScrollView来完成. 在默认情况下,ScrollView只是

Android搜索框/滚动视图/notification

1.搜索框(SearchView)的功能与用法 SearchView是搜索组件,其可以让用户在文本框内输入文件,并允许通过监听器监听用户输入.当用户输入完成后提交搜索,可通过监听器执行实际的搜索. 常用方法如下: ◆setIconfiedByDefault(boolean iconified):设置该搜索框默认是否自动缩小为图标; ◆setSubmitButtonEnabled(boolean enabled):设置是否显示搜索按钮; ◆setQueryHint(CharSequence hin

Android 自学之画廊视图(Gallery)功能和用法

Gallery与之前讲的Spinner有共同的父类:AbsSpinner,表明Gallery和Spinner都是一个列表框.他们之间的区别在于Spinner显示的是一个垂直的列表框,而Gallery显示的是一个水平的列表框.Gallery与Spinner有一个区别:Spinner的作用是供用户选择,而Gallery则允许用户通过拖动来查看上一个.下一个列表项. Gallery常用的XML属性及相关方法 XML属性 相关方法 说明 android:animationDuration setAnim

制作滚动视图(ScrollView)

怎样判断是否应当使用滚动视图 所谓的滚动视图,是指一个可以滑动的视窗,视窗大小和位置固定不变,视窗内的内容用户可以通过手指滑动或者拖动滚动天来进行滚动浏览. 滚动视图的目的是为了解决同类内容过多,一个UI版面显示不下的情况.如果同类内容过多,一般可以采取设置多个页面,然后通过翻页浏览的方式来浏览,但是很明显,滚动视图会比翻页更方便,因为在移动上可以很方便地花瓶进行滚动,在PC上可以通过鼠标的滚动进行滚动. 当需要判断是否应该使用滚动视图制作UI时,可以遵循以下规律: (1)有很多同类内容一个版面

Unity3d UGUI 滚动视图ScrollView的使用教程之简易背包

Unity3d中,UGUI提供了 Scroll Rect.Grid Layout Group.Mask这三个组件,我们用来实现滚动视图,这里用一个简易的背包作为示例. 文章转自 http://blog.csdn.net/huutu/  星环游戏 http://www.thisisgame.com.cn 首先我们放置好背包的底层方框,如下图. 我们在红色的那一块,作为物品栏的滑动区域.   文章转自 http://blog.csdn.net/huutu/  星环游戏 http://www.this

Android学习-滚动视图ScrollView和HorizontalScrollView

一.简介: ScrollView,通过官方文档的继承关系可以看出,它继承自FrameLayout,所以它是一种特殊类型的FrameLayout,因为它可以使用用户滚动显示一个占据的空间大于物理显示的视图列表.值得注意的是,ScrollView只能包含一个子视图或视图组,在实际项目中,通常包含的是一个垂直的LinearLayout. 二.ScrollView代码块: 在activity_main.xml中添加一个超出页面范围的按钮: <LinearLayout xmlns:android="

Android布局 屏幕滚动方法 ScrollView

ScrollView标签要放到最外层,事例: <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match

Android中通过Java代码实现ScrollView滚动视图-以歌词滚动为例

场景 实现效果如下 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书.教程推送与免费下载. 实现 将布局改为LinearLayout,并通过android:orientation="vertical">设置为垂直布局,然后添加id属性,并设置内边距 <?xml version="1.0" encoding="utf-8"?> <L

步步为营_Android开发课[25]_用户界面之ScrollView(滚动视图)

Focus on technology, enjoy life!-- QQ:804212028 浏览链接:http://blog.csdn.net/y18334702058/article/details/44624305 主题:用户界面之ScrollView(滚动视图) - ScrollView滚动视图实例: activity_main.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayo