畫廊視圖(Gallery)表示,能夠按水平方向顯示內(nèi)容,并且可用手指直接拖動圖片移動,一般用來瀏覽圖片,被選中的選項(xiàng)位于中間,并且可以響應(yīng)事件顯示信息。在使用畫廊視圖時(shí),首先需要在屏幕上添加Gallery組件,通常使用<Gallery>標(biāo)記在XML布局文件中添加。其基本語法如下:
<Gallery
屬性列表
>
</Gallery>
Gallery組件支持的XML屬性表如下:
android:animationDuration 用于設(shè)置列表切換時(shí)的動畫持續(xù)時(shí)間
android:gravity 用于設(shè)置對其方式
android:spacing 用于設(shè)置列表之間的間距
android:unselectedAlpha 用于設(shè)置沒有選中的列表項(xiàng)的透明度
使用畫廊視圖,也需要使用Adapter提供要顯示的數(shù)據(jù)。通常使用BaseAdapter類為Gallery組件提供數(shù)據(jù)。下面通過一個(gè)具體的實(shí)例演示通過BaseAdapter適配器為Gallery組件提供要顯示的圖片。
res/layout/main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:id="@+id/layout" android:gravity="center"> <Gallery android:id="@+id/gallery1" android:spacing="5px" android:unselectedAlpha="0.6" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout>
文章名稱:Android高級組件Gallery畫廊視圖使用方法詳解-創(chuàng)新互聯(lián)
URL分享:http://sd-ha.com/article48/jcpep.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、自適應(yīng)網(wǎng)站、服務(wù)器托管、品牌網(wǎng)站制作、小程序開發(fā)、用戶體驗(yàn)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容