当前位置:首页 > 开发 > 移动开发 > 正文

viewFlow实现类似淘宝的自动播放

发表于: 2013-12-31   作者:j2115126   来源:转载   浏览:
摘要:   ImageAdapter.java /* * Copyright (C) 2011 Patrik �kerfeldt * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compl
 
 

 

ImageAdapter.java
/*
 * Copyright (C) 2011 Patrik �kerfeldt
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.viewflowtest.cjy;

import java.util.List;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.Toast;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.yooeee.ziyoutong.R;

public class ImageAdapter extends BaseAdapter {
//	private DisplayImageOptions options;
	protected ImageLoader imageLoader;
	private Context mContext;
	private List<String> list;
	private LayoutInflater mInflater;

	public ImageAdapter(Context context,List<String> list) {
		mContext = context;
		this.list = list;
		imageLoader = imageLoader.getInstance();
//		options = new DisplayImageOptions.Builder().showStubImage(R.drawable.ic_launcher).showImageForEmptyUri(R.drawable.ic_launcher).showImageOnFail(R.drawable.ic_launcher).cacheInMemory().cacheOnDisc().displayer(new RoundedBitmapDisplayer(15)).build();
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return Integer.MAX_VALUE;   //返回很大的值使得getView中的position不断增大来实现循环
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.image_item, null);
		}
		ImageView imageView = ((ImageView) convertView.findViewById(R.id.imgView));
		imageLoader.displayImage(list.get(position%list.size()), imageView);
		convertView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Toast.makeText(mContext, "" + position, Toast.LENGTH_SHORT).show();
//				Intent intent = new Intent(mContext,ABSclass.class);
				Bundle bundle = new Bundle();
				bundle.putString("image_id", list.get(position%list.size()));
//				intent.putExtras(bundle);
//				mContext.startActivity(intent);
			}
		});
		return convertView;
	}

}
 
application中
@Override
	public void onCreate() {
		// 初始化下载图片jar包
		initImageLoader(getApplicationContext());
	}

	public static void initImageLoader(Context context)
	{
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory().discCacheFileNameGenerator(new Md5FileNameGenerator()).tasksProcessingOrder(QueueProcessingType.LIFO).enableLogging().build();

		ImageLoader.getInstance().init(config);
	}
 在你用的activity中加入
  viewFlow = (ViewFlow)findViewById(R.id.viewflow);
        viewFlow.setAdapter(new ImageAdapter(this));
        viewFlow.setmSideBuffer(3); // 实际图片张数, 我的ImageAdapter实际图片张数为3
        
        CircleFlowIndicator indic = (CircleFlowIndicator) findViewById(R.id.viewflowindic);
        viewFlow.setFlowIndicator(indic);
        viewFlow.setTimeSpan(4500);
        viewFlow.setSelection(3*1000);	//设置初始位置
        viewFlow.startAutoFlowTimer();  //启动自动播放
 
传个源码和网络获取图片的jar包

 

 

viewFlow实现类似淘宝的自动播放

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
首先这里先声明引用了开源库viewflow,我这里只用了其中的ViewFlow和CircleFlowIndicator。想对view
转载至http://xuzhihong1987.blog.163.com/blog/static/267315872011822113131823/ 概要: 本文将讲
这个插件的名字elevatezoom,网址为http://www.elevateweb.co.uk/image-zoom,在github上的项目首页
效果如下: 工程截图: 大致介绍下做法: 1.图片使用的是.9.png,这样图片就不会失真了。 2.拦截Lis
效果如下: 工程截图: 大致介绍下做法: 1.图片使用的是.9.png,这样图片就不会失真了。 2.拦截Lis
最近小项目中需要解决一些抗锯齿的问题,刚接触这个的时候查了很多资料,这里特别感觉一个朋友,谢
要做一个类似于淘宝的购物车功能。购物车一般会通过类似于cookie的功能实现。淘宝的购物车功能的特
  淘宝圈子首页(TechWeb配图)    淘宝圈子母婴频道(TechWeb配图)   3月27日消息,淘宝网推出
注意ViewFlow不是google官方的api,它是gethub上的一个开源项目,利用ViewFlow可以产生视图切换的效
完成这个例子的步骤: 1.下载ViewFlow的源码,然后将类ViewFlow放在自己的工程的src的某个包下。 2.
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号