HorizontalScrollView水平滾動(dòng)控件使用方法詳解
一、簡(jiǎn)介
用法ScrollView大致相同

二、方法
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)效果圖:


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)效果圖


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í)有所幫助,也希望大家多多支持腳本之家。
- Android自定義HorizontalScrollView實(shí)現(xiàn)qq側(cè)滑菜單
- Android HorizontalScrollView左右滑動(dòng)效果
- Android UI系列-----ScrollView和HorizontalScrollView的詳解
- Android HorizontalScrollView內(nèi)子控件橫向拖拽實(shí)例代碼
- Android利用HorizontalScrollView仿ViewPager設(shè)計(jì)簡(jiǎn)單相冊(cè)
- Android自定義HorizontalScrollView打造超強(qiáng)Gallery效果
- Android中HorizontalScrollView使用方法詳解
- Android使用自定義控件HorizontalScrollView打造史上最簡(jiǎn)單的側(cè)滑菜單
- Android中實(shí)現(xiàn)多行、水平滾動(dòng)的分頁(yè)的Gridview實(shí)例源碼
- android listview 水平滾動(dòng)和垂直滾動(dòng)的小例子
相關(guān)文章
android 獲取文件的擴(kuò)展名和去掉文件擴(kuò)展名的小例子
android 獲取文件的擴(kuò)展名和去掉文件擴(kuò)展名的小例子,需要的朋友可以參考一下2013-06-06
android 仿微信demo——微信通訊錄界面功能實(shí)現(xiàn)(移動(dòng)端,服務(wù)端)
本系列文章主要介紹了微信小程序-閱讀小程序?qū)嵗╠emo),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧,希望能給你們提供幫助2021-06-06
Android優(yōu)質(zhì)索尼滾動(dòng)相冊(cè)
這篇文章主要介紹了Android優(yōu)質(zhì)索尼滾動(dòng)相冊(cè),桌面小部件滾動(dòng)相冊(cè),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09
Android編程實(shí)現(xiàn)AlertDialog自定義彈出對(duì)話(huà)框的方法示例
這篇文章主要介紹了Android編程實(shí)現(xiàn)AlertDialog自定義彈出對(duì)話(huà)框的方法,結(jié)合實(shí)例形式分析了Android AlertDialog自定義彈出對(duì)話(huà)框的基本功能與事件監(jiān)聽(tīng)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-07-07
Android中ViewPager獲取當(dāng)前顯示的Fragment
這篇文章主要介紹了Android中ViewPager獲取當(dāng)前顯示的Fragment的兩種方法,一種是使用 getSupportFragmentManager().findFragmentByTag()方法,另一種是重寫(xiě)適配器的 setPrimaryItem()方法,有需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-01-01
Android第三方文件選擇器aFileChooser使用方法詳解
這篇文章主要介紹了Android第三方文件選擇器aFileChooser的使用方法詳解,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
Android開(kāi)發(fā)自定義雙向SeekBar拖動(dòng)條控件
這篇文章主要為大家介紹了Android開(kāi)發(fā)自定義雙向SeekBar拖動(dòng)條控件使用實(shí)例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06
Android實(shí)現(xiàn)View滑動(dòng)的6種方式
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)View滑動(dòng)的6種方式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05
Android自定義控件實(shí)現(xiàn)按鈕滾動(dòng)選擇效果
這篇文章主要為大家詳細(xì)介紹了Android自定義控件實(shí)現(xiàn)按鈕滾動(dòng)選擇效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-07-07
WheelView實(shí)現(xiàn)上下滑動(dòng)選擇器
這篇文章主要為大家詳細(xì)介紹了WheelView實(shí)現(xiàn)上下滑動(dòng)選擇器的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12

