實(shí)現(xiàn)循環(huán)顯示圖像的Gallery組件
<!--[endif]-->
在本節(jié)將組出與循環(huán)顯示圖像相關(guān)的ImageAdapter類的完整代碼。讀者可以從中看到上一節(jié)介紹的兩點(diǎn)改進(jìn)。為了使界面看上去更豐滿,本例還在單擊某一個(gè)Gallery組件中的圖像時(shí)在下方顯示一個(gè)放大的圖像(使用ImageSwitcher組件)。本例的顯示效果如圖3所示。當(dāng)不斷向后移動(dòng)圖像時(shí),圖像可不斷顯示,讀者可以自己運(yùn)行本例來體驗(yàn)一下。
<!--[endif]-->
在main.xml文件中定義的Gallery和ImageSwitcher組件的代碼如下:
代碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Gallery android:id="@+id/gallery" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_marginTop="30dp" />
<ImageSwitcher android:id="@+id/imageswitcher"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginTop="30dp" />
</LinearLayout>
本文導(dǎo)航
- 第1頁(yè): 首頁(yè)
- 第2頁(yè): 這些圖像的資源ID都保存在int數(shù)組中
- 第3頁(yè): 循環(huán)顯示圖像的原理
- 第4頁(yè): 實(shí)現(xiàn)循環(huán)顯示圖像的Gallery組件
- 第5頁(yè): 本例中Main類的完整代碼