`
malong26
  • 浏览: 167040 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Android 广告滚动条实现

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

直接打成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 楼 xuminliang 2014-02-18  
能否给广告滚动条添加事件监听呢,如何添加呢,我试着用一般的给控件添加事件监听的方式,不起效果啊
9 楼 corvin83 2013-07-12  
这个跟京东什么的不一样啊,他们我看是gallery或者viewpager实现的
8 楼 liang567 2013-05-04  
运行出错,怎么回事。我还以为我搞错了
7 楼 malong26 2012-12-27  
醉夕陽 写道
怎么导入到Eclipse运行不起来,说 这一行<com.autoplay.AutoPlayGallery  >出错 ,能否提供源码,打成jar 包啊, 源码提供出来修改,更好

邮箱258255419@qq.com

好久之前的代码了,写的不好,传上去了,你下载附件吧。
6 楼 醉夕陽 2012-12-26  
怎么导入到Eclipse运行不起来,说 这一行<com.autoplay.AutoPlayGallery  >出错 ,能否提供源码,打成jar 包啊, 源码提供出来修改,更好

邮箱258255419@qq.com
5 楼 醉夕陽 2012-12-26  
怎么导入到Eclipse运行不起来,说 这一行<com.autoplay.AutoPlayGallery  >出错
邮箱258255419@qq.com
4 楼 malong26 2012-12-05  
学会做人 写道
没有必要打成jar 包啊, 源码提供出来修改,更好

留下邮箱发给你
3 楼 学会做人 2012-12-04  
没有必要打成jar 包啊, 源码提供出来修改,更好
2 楼 malong26 2012-10-19  
BillKalin 写道
怎么导入到Eclipse运行不起来,说 这一行<com.autoplay.AutoPlayGallery  >出错,找不到这个AutoPlayGallery类,我导入了jar包啊

ADT17以下导入jar包还需要build path
ADT17以上自动build path
看看是不是这个问题
1 楼 BillKalin 2012-10-18  
怎么导入到Eclipse运行不起来,说 这一行<com.autoplay.AutoPlayGallery  >出错,找不到这个AutoPlayGallery类,我导入了jar包啊

相关推荐

Global site tag (gtag.js) - Google Analytics