Android ScrollView allows us to create a scrollable layout on the android screen.

Android ScrollView允许我们在android屏幕上创建可滚动的布局。

Android ScrollView (Android ScrollView)

ScrollView is a special type of FrameLayout that allows users to scroll through a list of views. It is useful when the layout occupies more space than the physical display. The ScrollView can contain only one child view or ViewGroup, which normally is a LinearLayout.

ScrollView是FrameLayout的一种特殊类型,它允许用户滚动视图列表。 当布局所占空间大于物理显示器时,此功能很有用。 ScrollView只能包含一个子视图或ViewGroup ,通常为LinearLayout 。

Note: Do not use a ListView together with the ScrollView. The ListView is designed to display a list of related information and is optimized for dealing with large lists. Also, ListView contains built-in scrolling capabilities.

注意 :请勿将ListView与ScrollView一起使用。 ListView旨在显示相关信息的列表,并已针对处理大型列表进行了优化。 另外,ListView包含内置的滚动功能。

  1. ScrollView only supports vertical scrolling. We have to use HorizontalScrollView for horizontal scrolling.ScrollView仅支持垂直滚动。 我们必须使用HorizontalScrollView进行水平滚动。
  2. The android:fillViewport property defines whether the scrollview should stretch its content to fill the viewport.android:fillViewport属性定义了scrollview是否应拉伸其内容以填充视口。

ScrollView XML布局 (ScrollView XML Layout)

<?xml version="1.0" encoding="utf-8"?>
<ScrollViewandroid:id="@+id/widget54"android:layout_width="fill_parent"android:layout_height="fill_parent"xmlns:android="https://schemas.android.com/apk/res/android"><LinearLayoutandroid:layout_width="310px"android:layout_height="wrap_content"android:orientation="vertical"><Buttonandroid:id="@+id/button1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="Back"/><Buttonandroid:id="@+id/button2"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="Button 1"/><Buttonandroid:id="@+id/button3"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="Button 2"/><TextViewandroid:text="This textView is placed inside a LinearLayout which is a child ViewGroup contained in a ScrollView"android:layout_width="fill_parent"android:textSize="18sp"android:layout_height="750px"/><Buttonandroid:id="@+id/button4"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="Button 3"/><Buttonandroid:id="@+id/button5"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="Button 4"/></LinearLayout>
</ScrollView>

We have explicitly assigned a larger size of the layout_height of the TextView so that ScrollView comes into use.

我们已明确分配了较大的TextView的layout_height大小,以便使用ScrollView。

Android ScrollView示例项目 (Android ScrollView Example Project)

This project consists of two Activities: MainActivity and SecondActivity.

该项目包括两个活动: MainActivitySecondActivity

The MainActivity displays the TableLayout.

MainActivity显示TableLayout。

package com.journaldev.layoutspartthree;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;public class MainActivity extends Activity {Button next;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.layout_table);next=(Button)findViewById(R.id.next);next.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent(MainActivity.this, SecondActivity.class);startActivity(intent);}});}@Overridepublic void onBackPressed() {finish();}
}

The SecondActivity.java contains the ScrollView with a LinearLayout inside it.

SecondActivity.java包含内部带有LinearLayout的ScrollView。

package com.journaldev.layoutspartthree;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;public class SecondActivity extends Activity {Button back;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.layout_scroll);back.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent= new Intent(SecondActivity.this,MainActivity.class);startActivity(intent);}});}
}

Output:

输出:

In the above image, the individual columns in all the three rows are highlighted.

在上图中,所有三行中的各个列都突出显示。

The vertical scrollbars are visible on the right side of the screen.

垂直滚动条在屏幕右侧可见。

AndroidScrollLayout.zipAndroidScrollLayout.zip

Reference: ScrollView Official Doc

参考: ScrollView官方文档

翻译自: https://www.journaldev.com/9531/android-scrollview

Android ScrollView相关推荐

  1. android图片保存形式,Android应用开发之Android ScrollView截图和图片保存到相册的方式...

    本文将带你了解Android应用开发之Android ScrollView截图和图片保存到相册的方式,希望本文对大家学Android有所帮助. 1.1首先来看你一种截取屏幕,这种代码有缺陷,只能截取一 ...

  2. Android两个tab吸顶,Android scrollView和viewpager嵌套 指示器吸顶 根据viewpager每

    Android scrollView和viewpager嵌套 指示器吸顶 根据viewpager每 Android scrollView和viewpager嵌套 指示器吸顶 根据viewpager每个 ...

  3. Android ScrollView嵌套ScrollView滚动的问题解决办法

    引用:http://mengsina.iteye.com/blog/1707464 http://fenglog.com/article.asp?id=449 Android ScrollView嵌套 ...

  4. Android ScrollView、NestedScrollView、Horizo​​ntalScrollView 等

    在这篇文章中,我们想看看几个滚动视图的变体或子类以及它们是如何使用的.以下是我们迄今为止涵盖的变体: ScrollView - 超类 NestedScrollView - 子类 Horizo​​nta ...

  5. Android ScrollView嵌套GridView导致GridView只显示一行item

    Android ScrollView嵌套GridView导致GridView只显示一行item Android ScrollView在嵌套GridView时候,会导致一个问题发生:GridView只显 ...

  6. Android ScrollView充满屏幕

    Android ScrollView充满屏幕 ScrollView充满屏幕 textAllCaps大小写 ScrollView充满屏幕 有时ScrollView的实际内容不够,又想让它充满屏幕. 如果 ...

  7. android scrollview 布局,Android scrollview实现底部继续拖动查看图文详情

    本文实例为大家分享了Android实现底部拖动查看图文详情的具体代码,供大家参考,具体内容如下 一.效果图 二.实现步骤 1.xml布局的实现/p> android:id="@+id/ ...

  8. android ScrollView实现上拉、下拉更新

    项目中需要实现对listView的上拉加载更多的功能,忙了一上午也没搞定,从网上看到一篇文章实现了listView的下拉功能,在参照着改的过程中,实现了另一种形式的上拉.下拉更新,参照文章http:/ ...

  9. android ScrollView 控制行数

    利用ScrollView 来控制textView 显示的行数 <ScrollViewandroid:layout_width="fill_parent"android:lay ...

最新文章

  1. 利用边缘检测计算物体面积(内含源码)
  2. DARPA发布产业振兴计划,继承摩尔智慧
  3. js 外部文件加载处理
  4. MATLAB中常用的排列、组合、阶乘函数
  5. SAP不同产品的UI开发策略概述
  6. 【操作系统】Semaphore处理吸烟者问题
  7. SpringBoot面试题第一弹
  8. 13.C#的函数练习
  9. CodeForces - 948C(前缀和 + 二分)
  10. 大数据之Python实现每日钉钉数据自动推送
  11. 服务器备案新增网站,已经备案服务器 增加新域名
  12. WPF Binding表达式
  13. 频繁默认网关不可用_老是默认网关不可用,默认网关不可用总掉线解决方法
  14. PDF Expert教程之批注功能详解
  15. 华为智慧屏的四大核心功能
  16. 学插画的线上机构排名
  17. window10下WSL使用Ubuntu报错: System has not been booted with systemd as init system (PID 1). Can‘t operat
  18. 嵌入式应用层开发要学习什么
  19. 如何从VDS明网下载钱包
  20. 如何掌控自己的时间和生活 ---阿兰·拉金

热门文章

  1. Linux 安装Nginx详细图解教程
  2. [BZOJ2733] [HNOI2012] 永无乡 (splay启发式合并)
  3. 课堂练习--最大子数组和
  4. Dapper入门学习
  5. 我的网站被黑了,关键词被劫持,总结一下是怎么解决的。
  6. AE “每用户订阅上的所有人SID 不存在”
  7. Windows phone 8 学习笔记(1) 触控输入
  8. [转载] java简易爬虫Crawler
  9. [转载] 了解Node.js-to-Angular 套件组件
  10. Django基础--4