Android 广告滚动条实现

各个商城类客户端都有滚动广告,比如京东,QQ,1号电,当当网等。主要功能是自动播放广告图片,带指示器,并支持滑动翻页。下面就是我对这个组件的实现:
[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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值