首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

gallery显示图片替换(手动和自动)

2012-08-27 
gallery显示图片轮换(手动和自动)1.gallery.xml?xml version1.0 encodingutf-8?LinearLayoutxmln

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;
}
}
};

热点排行