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

 更新时间:2017年08月10日 08:42:32   作者:饭饭_fan  
这篇文章主要为大家详细介绍了HorizontalScrollView水平滚动控件的使用方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

一、简介

用法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,保证了这个,怎么用也不会错

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

相关文章

  • Android中ImageView实现选择本地图片并显示功能

    Android中ImageView实现选择本地图片并显示功能

    本文主要介绍了android中ImageView实现选择本地图片并显示功能的示例代码。具有很好的参考价值。下面跟着小编一起来看下吧
    2017-04-04
  • Android实现简单图库辅助器

    Android实现简单图库辅助器

    这篇文章主要为大家详细介绍了Android实现简单图库辅助器的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-04-04
  • Android学习之Flux架构入门

    Android学习之Flux架构入门

    Flux是Facebook在14年提出的一种Web前端架构,主要用来处理复杂的UI逻辑的一致性问题(当时是为了解决Web页面的消息通知问题)。接下来从其特点和使用上来介绍Flux架构。本文主要目的是让你对Flux的一个架构大体面貌有个了解。
    2016-08-08
  • Android App中实现向右滑动销毁功能的要点解析

    Android App中实现向右滑动销毁功能的要点解析

    这篇文章主要介绍了Android应用中实现向右滑动销毁条目功能的要点解析,有些类似于iOS App中的滑动页面删除效果,需要的朋友可以参考下
    2016-04-04
  • Android编译的注意事项

    Android编译的注意事项

    今天小编就为大家分享一篇关于Android编译的注意事项,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
    2018-12-12
  • android viewflipper实现左右滑动切换显示图片

    android viewflipper实现左右滑动切换显示图片

    这篇文章主要为大家详细介绍了android viewflipper实现左右滑动切换显示图片,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-05-05
  • Android反编译程序整理详解

    Android反编译程序整理详解

    很多做安卓开发的朋友都在寻找好的反编译软件和方法,小编给大家整理的很多目前流行的Android反编译程序,希望能够给你提供参考。
    2017-11-11
  • Android数据加密之Des加密详解

    Android数据加密之Des加密详解

    DES是一种对称加密算法,所谓对称加密算法即:加密和解密使用相同密钥的算法,这篇文章主要介绍了Android Des加密,感兴趣的小伙伴们可以参考一下
    2016-08-08
  • Android Studio实现带三角函数对数运算功能的高级计算器

    Android Studio实现带三角函数对数运算功能的高级计算器

    这篇文章主要为大家详细介绍了Android Studio实现带三角函数对数运算功能的高级计算器,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-05-05
  • Android模拟器最新检测方法详解

    Android模拟器最新检测方法详解

    这篇文章主要介绍了Android模拟器的检测方法,在Android开发过程中,防作弊一直是老生常谈的问题,而模拟器的检测往往是防作弊中的重要一环,接下来我们来讲解有关于模拟器的检测方法,需要的朋友可以参考下
    2024-02-02

最新评论