gallery显示图片轮换(手动和自动)
1.gallery.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:cacheColorHint="#00000000"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/gallerylayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- 广告图片 -->
<Gallery android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="160dp"
android:spacing="1dp"
android:fadingEdge="none"
/>
<LinearLayout
android:orientation="vertical"
android:layout_gravity="bottom"
android:background="@drawable/boke_titlebg"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextSwitcher
android:id="@+id/TextSwitcher01"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TextSwitcher>
<LinearLayout
android:id="@+id/hintlayout"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
2.代码中添加
autoGallery = new Timer();
autoGallery.schedule(new TimerTask() {
@Override
public void run() {
if (gallerypisition < count - 1) {
gallerypisition = gallerypisition + 1;
} else {
gallerypisition = 0;
}
autoGalleryHandler.sendEmptyMessage(1);
}
}, 5000, 5000);
Handler autoGalleryHandler = new Handler() {
public void handleMessage(Message message) {
super.handleMessage(message);
switch (message.what)
{
case 1:
g.setSelection(gallerypisition);
break;
}
}
};