为什么要用ScrollView 滚动视图控件

应为手机屏幕过小显示的内容过多没法显示完全所以要使用滚动视图控件

使用时的注意点

  1. 不用再ScrollView内部使用自带滚动条的控件或布局

  2. ScrollView直接子View只能有一个

  3. ScrollView只支持竖直滑动 如果想要横向滑动 HorizontalScrollView

简单的使用

xml文件This XML file does not appear to have any style information associated with it. The document tree is shown below.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<Button android:id="@+id/btn_bottom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="跳转底部 "/>
<Button android:id="@+id/btn_top" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="返回顶部"/>
</LinearLayout>
<ScrollView android:id="@+id/sv" android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="顶部"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本2"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本3"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本4"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本5"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本6"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本7"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本8"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本9"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本10"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本11"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本2"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本3"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本4"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本5"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本6"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本7"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本8"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本9"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本10"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本11"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本2"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本3"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本4"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本5"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本6"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本7"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本8"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本9"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本10"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本11"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本2"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本3"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本4"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本5"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本6"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本7"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本8"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本9"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本10"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本11"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本6"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本7"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本8"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本9"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本10"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本11"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本2"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本3"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本4"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本5"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本6"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本7"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本8"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本9"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本10"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本11"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本2"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本3"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本4"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本5"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本6"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本7"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本8"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本9"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="文本10"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="底部"/>
</LinearLayout>
</ScrollView>
</LinearLayout>

点击事件

package com.hopu.demo;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ScrollView;public class MainActivity extends AppCompatActivity implements View.OnClickListener {// 第一步:声明容器private ScrollView scrollView;private Button btn_top;private Button btn_bottom;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// 第二步:根据ID获取页面上的控件,并把控件赋值给容器btn_top = findViewById(R.id.btn_top);btn_bottom = findViewById(R.id.btn_bottom);scrollView = findViewById(R.id.sv);// 第三步: 设置监听btn_top.setOnClickListener(this);btn_bottom.setOnClickListener(this);}// 对于监听的处理@Overridepublic void onClick(View v) {if (v.getId() == R.id.btn_top) {// 返回顶部scrollView.fullScroll(ScrollView.FOCUS_UP);} else if (v.getId() == R.id.btn_bottom) {// 跳转底部scrollView.fullScroll(ScrollView.FOCUS_DOWN);} else {}}
}

ScrollView 滚动视图控件相关推荐

  1. Android之ScrollView滚动布局控件使用以及显示新闻网页

    ScrollView滚动布局使用原理: ①滚动产生的条件是,里面的内容大于物理尺寸 ②ScrollView里面只有一个子元素,这个子元素就是一个线性布局LinearLayout,我们可以在线性布局中添 ...

  2. ReactNative进阶(二十五):ScrollView 滚动视图组件详解

    文章目录 一.概述 二.属性 2.1 Style 2.2 方法 2.2.1 scrollTo() 2.2.2 crollToEnd() 三.拓展阅读 一.概述 ScrollView在Android和i ...

  3. 【Android从零单排系列十一】《Android视图控件——日历、日期、时间选择控件》

    目录 一.日历.日期.时间组件基本介绍 二.几种常见的控件类型 1.CalendarView –日历控件 2. DatePicker –日期选择控件 3.TimePicker –时间选择控件 4.Ch ...

  4. GTK构件 --- 文本视图控件GTKtextview

    GTK构件 - 文本视图控件GTKtextview   文本视图控件(GtkTextView)是用以取代原有的文本编辑(GtkText)控件的,它包括一个文本缓冲区(GtkTextBuffer),用来 ...

  5. 嵌入式GUI LVGL『Tile View拼接视图控件』介绍

    一. LVGL GUI拼接视图控件的概念 Tileview是一个容器对象,其中的元素(称为tiles)可以以网格形式排列.通过滑动,用户可以在这些贴图之间导航. 如果Tileview是屏幕大小,它会提 ...

  6. VS2010/MFC编程入门之二十九(常用控件:列表视图控件List Control 下)

    上一节是关于列表视图控件List Control的上半部分,简单介绍了列表视图控件,其通知消息的处理和有关结构体的定义.本节继续讲解下半部分,包括列表视图控件的创建.CListCtrl类的主要成员函数 ...

  7. Win32 树视图控件的基本使用

    首先参阅 https://blog.csdn.net/bcbobo21cn/article/details/106287676 认识Windows公共控件库的使用: 一 创建树视图 首先用如下代码看一 ...

  8. linux sort -w32,WIN32汇编: 31.列表视图控件

    第三十一课 列表视图控件 本课中我们将学习如何创建和使用列表视图控件. 理论: 列表视图控件和树型视图.丰富文本编辑控件一样是通用控件的一种.可能您都已经知道了列表视图控件,只不过是不知道它的确切名字 ...

  9. LVITEM结构-列表视图控件的一个数据结构

    列表视图控件(List Control) 列表视图控件是一种非常常用的控件,在需要以报表形式显示数据时,列表控件通常是最好的选择,许多专用的数据报表控件,也是在它的基础上派生而来.与树视图类似,列表控 ...

最新文章

  1. 添加类iOS cocos2d 2游戏开发实战(第3版)
  2. 静态程序分析chapter5 - 常量传播分析上(Costant Propagation Analysis)
  3. [luogu3231 HNOI2013] 消毒 (二分图最小点覆盖)
  4. 教小学妹学算法:十大经典排序算法深度解析
  5. Zookeeper环境安装
  6. Codeforces Round #614 (Div. 2) D. Aroma‘s Search 暴力 + 思维
  7. Android学习按键事件监听与Command模式
  8. 看懂 ,学会 .NET 事件的正确姿势-简单版
  9. FFmpeg开发(一)常用处理视频命令
  10. 无线AP与无线路由器都有些什么区别?(二)
  11. Linux下安装lingo教程-centos6 64位
  12. node2vec 包安装
  13. 自适应弹出框-垂直居中
  14. mysql 通过经纬度查询附近的地点位置
  15. SaaS系统权限体系设计
  16. 千元机自拍新体验,vivo Z3是你会拍照的“男朋友”
  17. 计算机与投影仪的记录,投影仪和电脑的连接及PPT播放
  18. 用Python海归作图--turtle,画椭圆
  19. 功能类微信小程序的推广
  20. 奇技淫巧玄妙无穷| M1 mac os(苹果/AppleSilicon)系统的基本操作和设置

热门文章

  1. Sentinel生产环境实践
  2. 微课与个性化学习路径之浅谈
  3. 计算机图形学基础教程学习总结
  4. 【无标题】matlab正态分布函数积分
  5. USB设备绑定固定端口
  6. 湖州师范计算机学院女生宿舍,2018年湖州师范学院新生宿舍条件带空调,宿舍内部环境图片 - 高教网...
  7. JavaScript 事件对内存和性能的影响
  8. Rising Temperature
  9. 基于Java毕业设计影片租赁系统源码+系统+mysql+lw文档+部署软件
  10. pgdac和unidac插入效率究竟差多少?