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

HorizontalScrollView水平滚动控件使用方法详解,第1张

概述一、简介用法ScrollView大致相同二、方法1)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,保证了这个,怎么用也不会错

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

总结

以上是内存溢出为你收集整理的HorizontalScrollView水平滚动控件使用方法详解全部内容,希望文章能够帮你解决HorizontalScrollView水平滚动控件使用方法详解所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1144883.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存