文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Android组件ScrollView怎么使用

2023-06-29 19:05

关注

今天小编给大家分享一下Android组件ScrollView怎么使用的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

概述

    ScrollView也是一个容器,它是FrameLayout的子类,它的主要作用就是将超出物理屏幕的内容显示出来,(就是滚动条效果)ScrollView提供垂直滚动,进而可将超出物理屏幕的内容显示出来。

      在一般情况下,可以将一个采用垂直方式布局组件的LinearLayout作为ScrollLayout容器的子组件,同时,在LinearLayout容器中可以显示超出屏幕物理高度的内容。

练习

这么说有点抽象,然后我们现在实现完成一个调试板颜色的显示,效果如下:(可以往下滚动)

代码:

<?xml version="1.0" encoding="utf-8"?><ScrollView xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent">      <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="vertical">         <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal">            <View                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#07C2FB" />            <TextView                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#07C2FB" />        </LinearLayout>         <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal">            <View                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#C60426FD" />            <TextView                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#C60426FD" />        </LinearLayout>         <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal">            <View                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#032898" />            <TextView                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#032898" />        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal">            <View                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#021173" />            <TextView                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#021173" />        </LinearLayout>         <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal">            <View                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#504DAE" />            <TextView                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#504DAE" />        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal">            <View                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#3C60A6" />            <TextView                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#3C60A6" />        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal">            <View                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#282EA8" />            <TextView                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#282EA8" />        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal">            <View                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#273523" />            <TextView                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="##5E7559" />        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal">            <View                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#0E1E73" />            <TextView                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#0E1E73" />        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal">            <View                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#305BC8" />            <TextView                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#305BC8" />        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal">            <View                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#282EA8" />            <TextView                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#282EA8" />        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal">            <View                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#0B685E" />            <TextView                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#0B685E" />        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal">            <View                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#263B7E" />            <TextView                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#263B7E" />        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal">            <View                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#0A7AC5" />            <TextView                android:layout_width="0dp"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#0A7AC5" />        </LinearLayout>     </LinearLayout> </ScrollView>

Android组件ScrollView怎么使用

      当然了ScrollView只提供了垂直滚动条,若要使用水平滚动功能,则Android提供了HorizontalScrollView容器,HorizontalScrollView容器可以提供水平滚动,它的使用方法与ScrollView类似

HorizontalScrollView:

<?xml version="1.0" encoding="utf-8"?><HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent">      <LinearLayout        android:layout_width="wrap_content"        android:layout_height="match_parent"        android:orientation="horizontal">         <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <View                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#2479CE" />             <TextView                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#2479CE" />        </LinearLayout>         <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <View                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#C97A06" />             <TextView                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#C97A06" />        </LinearLayout>         <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <View                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#68060E" />             <TextView                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#68060E" />        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <View                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#271904" />             <TextView                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#271904" />        </LinearLayout>          <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <View                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#673AB7" />             <TextView                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#673AB7" />        </LinearLayout>         <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <View                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#1B5834" />             <TextView                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#1B5834" />        </LinearLayout>         <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <View                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#680379" />             <TextView                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#680379" />        </LinearLayout>         <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <View                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#043485" />             <TextView                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#043485" />        </LinearLayout>         <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <View                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#798506" />             <TextView                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#798506" />        </LinearLayout>         <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <View                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#B12E04" />             <TextView                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#B12E04" />        </LinearLayout>         <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <View                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#A09006" />             <TextView                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#A09006" />        </LinearLayout>         <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <View                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="2"                android:background="#920C02" />             <TextView                android:layout_width="200px"                android:layout_height="60dp"                android:layout_weight="1"                android:gravity="center"                android:text="#920C02" />        </LinearLayout>      </LinearLayout> </HorizontalScrollView>

 实现效果:

Android组件ScrollView怎么使用

以上就是“Android组件ScrollView怎么使用”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注编程网行业资讯频道。

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     801人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     348人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     311人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     432人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     220人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯