溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

HorizontalScrollView水平滾動(dòng)控件使用方法詳解

發(fā)布時(shí)間:2020-09-07 22:01:28 來源:腳本之家 閱讀:1293 作者:飯飯_fan 欄目:移動(dòng)開發(fā)

一、簡(jiǎn)介

用法ScrollView大致相同

HorizontalScrollView水平滾動(dòng)控件使用方法詳解

二、方法

1)HorizontalScrollView水平滾動(dòng)控件使用方法

1、在layout布局文件的最外層建立一個(gè)HorizontalScrollView控件

2、在HorizontalScrollView控件中加入一個(gè)LinearLayout控件,并且把它的orientation設(shè)置為horizontal

3、在LinearLayout控件中放入多個(gè)裝有圖片的ImageView控件 

2)HorizontalScrollView和ScrollView混合使用方法

 以先垂直后水平為例

1、在layout布局文件的最外層建立一個(gè)ScrollView控件

2、在ScrollView控件中加入一個(gè)LinearLayout控件,并且把它的orientation設(shè)置為vertical

3、在這個(gè)LinearLayout中添加多個(gè)已經(jīng)弄好的HorizontalScrollView水平滾動(dòng)控件 

三、代碼實(shí)例

HorizontalScrollView水平滾動(dòng)控件使用方法

1、水平滾動(dòng)效果圖:

HorizontalScrollView水平滾動(dòng)控件使用方法詳解

HorizontalScrollView水平滾動(dòng)控件使用方法詳解

2、水平滾動(dòng)代碼:

/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、水平豎直混合滾動(dòng)效果圖

HorizontalScrollView水平滾動(dòng)控件使用方法詳解HorizontalScrollView水平滾動(dòng)控件使用方法詳解

3、水平豎直混合滾動(dòng)效果代碼

/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>

四、注意點(diǎn)

 1、始終注意HorizontalScrollView和ScrollView的直接兒子只有一個(gè),一般都是LinearOut,保證了這個(gè),怎么用也不會(huì)錯(cuò)

 以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI