各个商城类客户端都有滚动广告,比如京东,QQ,1号电,当当网等。主要功能是自动播放广告图片,带指示器,并支持滑动翻页。下面就是我对这个组件的实现:
[img]http://dl.iteye.com/upload/picture/pic/115298/f88efa71-9626-33c3-8290-2050a968c991.png[/img]
直接打成jar包提供使用。下面是一些公共方法:
下面是我使用的一个demo代码:
布局文件:
[img]http://dl.iteye.com/upload/picture/pic/115298/f88efa71-9626-33c3-8290-2050a968c991.png[/img]
直接打成jar包提供使用。下面是一些公共方法:
//设置Adapter并开始自动播放
setAdapter(ImageAdapter adapter)
//停止播放
stop()
//判断是否在播放,返回boolean
isPlaying()
//设置播放间隔时间
setDuration(int duration)
下面是我使用的一个demo代码:
package com.compnent;
import java.util.ArrayList;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import com.autoplay.AutoPlayGallery;
import com.autoplay.ImageAdapter;
import com.autoplay.R;
public class AutoPlayDemoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AutoPlayGallery g = (AutoPlayGallery) findViewById(R.id.autoGallery);
ArrayList<Drawable> drawables = new ArrayList<Drawable>();
drawables.add(getResources().getDrawable(R.drawable.tuijian_001));
drawables.add(getResources().getDrawable(R.drawable.tuijian_002));
drawables.add(getResources().getDrawable(R.drawable.tuijian_003));
ImageAdapter adapter = new ImageAdapter(this, drawables);
g.setAdapter(adapter);
}
}
布局文件:
<?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">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<com.autoplay.AutoPlayGallery
android:id="@+id/autoGallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<ImageView
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>