HorizontalScrollView水平滚动控件使用方法详解

发布时间 - 2026-01-11 02:43:21    点击率:

一、简介

用法ScrollView大致相同

二、方法

1)HorizontalScrollView水平滚动控件使用方法

1、在layout布局文件的最外层建立一个HorizontalScrollView控件

2、在HorizontalScrollView控件中加入一个LinearLayout控件,并且把它的orientation设置为horizontal

3、在LinearLayout控件中放入多个装有图片的ImageView控件 

2)HorizontalScrollView和ScrollView混合使用方法

 以先垂直后水平为例

1、在layout布局文件的最外层建立一个ScrollView控件

2、在ScrollView控件中加入一个LinearLayout控件,并且把它的orientation设置为vertical

3、在这个LinearLayout中添加多个已经弄好的HorizontalScrollView水平滚动控件 

三、代码实例

HorizontalScrollView水平滚动控件使用方法

1、水平滚动效果图:

2、水平滚动代码:

/Ex27ScrollView/res/layout/activity02.xml

<?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"
  android:scrollbars="none"
  >
  <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    >
    <ImageView 
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/item1"
      />
    <ImageView 
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/item2"
      />
    <ImageView 
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/item3"
      />
    <ImageView 
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/item4"
      />
    <ImageView 
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/item5"
      />
  </LinearLayout>
  

</HorizontalScrollView>

3、水平竖直混合滚动效果图

3、水平竖直混合滚动效果代码

/Ex27ScrollView/res/layout/activity03.xml

<?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"
  android:scrollbars="none" >

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <HorizontalScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:scrollbars="none" >

      <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item1" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item2" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item3" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item4" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item5" />
      </LinearLayout>
    </HorizontalScrollView>
    <HorizontalScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:scrollbars="none" >

      <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item1" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item2" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item3" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item4" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item5" />
      </LinearLayout>
    </HorizontalScrollView>
    <HorizontalScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:scrollbars="none" >

      <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item1" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item2" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item3" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item4" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item5" />
      </LinearLayout>
    </HorizontalScrollView>
    <HorizontalScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:scrollbars="none" >

      <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item1" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item2" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item3" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item4" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item5" />
      </LinearLayout>
    </HorizontalScrollView>
    <HorizontalScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:scrollbars="none" >

      <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item1" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item2" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item3" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item4" />

        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/item5" />
      </LinearLayout>
    </HorizontalScrollView>
  </LinearLayout>

</ScrollView>

四、注意点

 1、始终注意HorizontalScrollView和ScrollView的直接儿子只有一个,一般都是LinearOut,保证了这个,怎么用也不会错

 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


# HorizontalScrollView  # 水平滚动控件  # Android自定义HorizontalScrollView实现qq侧滑菜单  # Android HorizontalScrollView左右滑动效果  # Android UI系列-----ScrollView和HorizontalScrollView的详  # Android HorizontalScrollView内子控件横向拖拽实例代码  # Android利用HorizontalScrollView仿ViewPager设计简单相册  # Android自定义HorizontalScrollView打造超强Gallery效果  # Android中HorizontalScrollView使用方法详解  # Android使用自定义控件HorizontalScrollView打造史上最简单的侧滑菜单  # Android中实现多行、水平滚动的分页的Gridview实例源码  # android listview 水平滚动和垂直滚动的小例子  # 多个  # 建立一个  # 设置为  # 都是  # 最外层  # 在这个  # 只有一个  # 为例  # 弄好  # 大家多多  # pre  # text  # style  # Ex27ScrollView  # class  # res  # center  # align  # xml  # layout 


相关栏目: 【 网站优化151355 】 【 网络推广146373 】 【 网络技术251813 】 【 AI营销90571


相关推荐: CSS3怎么给轮播图加过渡动画_transition加transform实现【技巧】  如何在阿里云通过域名搭建网站?  微信小程序 canvas开发实例及注意事项  如何自定义safari浏览器工具栏?个性化设置safari浏览器界面教程【技巧】  php485函数参数是什么意思_php485各参数详细说明【介绍】  手机网站制作与建设方案,手机网站如何建设?  详解Nginx + Tomcat 反向代理 如何在高效的在一台服务器部署多个站点  个人网站制作流程图片大全,个人网站如何注销?  微信小程序 input输入框控件详解及实例(多种示例)  Laravel Session怎么存储_Laravel Session驱动配置详解  详解Nginx + Tomcat 反向代理 负载均衡 集群 部署指南  宙斯浏览器视频悬浮窗怎么开启 边看视频边操作其他应用教程  百度输入法ai组件怎么删除 百度输入法ai组件移除工具  如何快速搭建高效简练网站?  如何确保西部建站助手FTP传输的安全性?  Laravel如何处理JSON字段_Eloquent原生JSON字段类型操作教程  太平洋网站制作公司,网络用语太平洋是什么意思?  宙斯浏览器文件分类查看教程 快速筛选视频文档与图片方法  高防服务器租用指南:配置选择与快速部署攻略  Laravel用户密码怎么加密_Laravel Hash门面使用教程  Laravel如何使用Service Container和依赖注入?(代码示例)  PythonWeb开发入门教程_Flask快速构建Web应用  jquery插件bootstrapValidator表单验证详解  微博html5版本怎么弄发语音微博_语音录制入口及时长限制操作【教程】  如何用景安虚拟主机手机版绑定域名建站?  Edge浏览器提示“由你的组织管理”怎么解决_去除浏览器托管提示【修复】  Win11怎么设置虚拟桌面 Win11新建多桌面切换操作【技巧】  重庆市网站制作公司,重庆招聘网站哪个好?  Edge浏览器如何截图和滚动截图_微软Edge网页捕获功能使用教程【技巧】  Laravel定时任务怎么设置_Laravel Crontab调度器配置  Laravel如何发送系统通知?(Notification渠道示例)  怎样使用JSON进行数据交换_它有什么限制  如何在建站主机中优化服务器配置?  活动邀请函制作网站有哪些,活动邀请函文案?  如何有效防御Web建站篡改攻击?  香港服务器网站生成指南:免费资源整合与高速稳定配置方案  如何快速登录WAP自助建站平台?  网站制作报价单模板图片,小松挖机官方网站报价?  iOS发送验证码倒计时应用  Laravel如何实现数据库事务?(DB Facade示例)  大学网站设计制作软件有哪些,如何将网站制作成自己app?  如何在万网自助建站中设置域名及备案?  Laravel怎么实现一对多关联查询_Laravel Eloquent模型关系定义与预加载【实战】  JavaScript如何实现倒计时_时间函数如何精确控制  EditPlus中的正则表达式实战(6)  Laravel如何使用查询构建器?(Query Builder高级用法)  JavaScript模板引擎Template.js使用详解  如何获取PHP WAP自助建站系统源码?  googleplay官方入口在哪里_Google Play官方商店快速入口指南  如何做网站制作流程,*游戏网站怎么搭建?