各个商城类客户端都有滚动广告,比如京东,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>
分享到:
相关推荐
Android自定义View——仿1号店垂直滚动广告条实现 Android自定义View——仿1号店垂直滚动广告条实现
Android自动滚动广告条,通过覆写ViewPager来实现循环滚动,支持开始、暂停/继续、停止。可根据需要进行定制。
有些应用里面会有一些上下滚动文字的广告,尤其是关于商城里面的容易出现,具体的效果相比大家也见过,TextSwitche
使用ViewFlipper实现Android仿淘宝头条滚动广告条,http://blog.csdn.net/qq_35605213/article/details/79564914
本篇文章主要介绍了Android_RecyclerView实现上下滚动广告条实例(带图片),具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本篇文章主要介绍了Android滚动条广告实现代码示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
实现广告条滚动手动+自动+无限循环+完美平滑过渡三个例子ViewPager
在一些类似于淘宝的电商网站上经常能够看到一些滚动的广告条,许多软件在首页也有类似的广告条,如图: 实现起来并不是很复杂的,结合网上的一些教程,实现了现在这样一个可以几张图循环播放,并且可以手指滑动切换...
此demo为仿淘宝头条中,文字的垂直滚动显示效果,主要用到的是Android原生控件ViewFlipper,详情可参考我的博客地址:http://blog.csdn.net/sophie237/article/details/54911349
项目中需要用到类似公告栏的控件,能用的基本不支持多行显示,于是只好自己动手,苦于没有自定义过一个像样的控件,借鉴Android公告条demo,实现了多行向上滚动的控件。在原控件基础之上添加如下功能: •传入数据...
一句话实现Banner的广告条
主要介绍了Android自定义View实现仿1号店垂直滚动广告条代码,实现步骤及实现原理本文给大家介绍的非常详细,需要的朋友参考下吧
ViewPager+Fragment的用法在android开发中比较常见,最近刚好要实现这个功能,写个笔记记录下来,以供参考。
在一些电子商务网站上经常能够看到一些滚动的广告条,许多软件在首次使用时也有类似的广告条,如图: 其实在github上有实现这种效果的控件,不过这东西做起来也是很简单,我们今天就来看看该怎么做。 先来看看布局...
主要为大家详细介绍了Android控件ViewFlipper仿淘宝头条垂直滚动广告条,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
Android垂直滚动广告条效果源码,实现类似于淘宝样式的垂直广告滚动条