码迷,mamicode.com
首页 > 其他好文 > 详细

cc_美团 商品详情图片放大显示ViewPager

时间:2015-07-16 14:20:00      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:图片放大viewpager

技术分享


package com.chencheng.meituan.view;


import java.util.ArrayList;

import java.util.List;

import com.xinbo.widget.HackyViewPager;

import android.app.Activity;

import android.graphics.Bitmap;

import android.graphics.drawable.Drawable;

import android.os.Bundle;

import android.support.v4.view.PagerAdapter;

import android.support.v4.view.ViewPager;

import android.util.Log;

import android.view.Menu;

import android.view.View;

import android.view.ViewGroup;

import android.view.ViewGroup.LayoutParams;

import uk.co.senab.photoview.PhotoView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;

import com.nostra13.universalimageloader.core.ImageLoader;

import com.nostra13.universalimageloader.core.assist.FailReason;

import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

import com.xinbo.utils.BitmapUtils;

import com.yuchen.meituan.R;


public class ShowImgActivity extends Activity {


private List<Drawable> mPics = new ArrayList<Drawable>();

private List<String> mImgURLs = new ArrayList<String>();

private ViewPager mViewPager;

private DisplayImageOptions options;

private Drawable mDrawable;

private String mImageUrl;

private MyPagerAdapter mPagerAdapter;


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_view_pager);

mImageUrl = getIntent().getStringExtra("imageUrl");

initUIL();

initViewPager();

}


private void initViewPager() {

mViewPager = (HackyViewPager) findViewById(R.id.view_pager);

setContentView(mViewPager);

mPagerAdapter = new MyPagerAdapter();

loadPic();

// mViewPager.setAdapter(mPagerAdapter);

}


private void loadPic() {

Log.e("loadPic", "mImageUrl = " + mImageUrl);

ImageLoader.getInstance().loadImage(mImageUrl, options,

new ImageLoadingListener() {

@Override

public void onLoadingStarted(String arg0, View arg1) {

}


@Override

public void onLoadingFailed(String arg0, View arg1,

FailReason arg2) {

}


@Override

public void onLoadingComplete(String arg0, View arg1,

Bitmap arg2) {

mDrawable = BitmapUtils.bitmap2Drawable(arg2);

mViewPager.setAdapter(mPagerAdapter);

}


@Override

public void onLoadingCancelled(String arg0, View arg1) {

}

});

}


private void initUIL() {

options = new DisplayImageOptions.Builder()

.showImageOnLoading(R.drawable.ic_review_score_tip_excellent_off)

// 设置图片在下载期间显示的默认图片

.showImageForEmptyUri(R.drawable.ic_review_score_tip_excellent_off)

// 设置URI错误或者为空时显示的图片

.showImageOnFail(R.drawable.ic_review_score_tip_excellent_off)

// 设置图片加载或者解析出现错误时设置的图片

.cacheInMemory(true)

// 是否内存缓存

.cacheOnDisk(true)

// 是否外存缓存

.considerExifParams(true)

// .displayer(new RoundedBitmapDisplayer(100))// 是否设置图片圆角

.displayer(new FadeInBitmapDisplayer(200))// 图片加载好之后渐入的时间

.build();

}


class MyPagerAdapter extends PagerAdapter {

@Override

public int getCount() {

return 3;

}


@Override

public boolean isViewFromObject(View view, Object object) {

return view == object;

}


@Override

public Object instantiateItem(ViewGroup container, int position) {

PhotoView photoView = new PhotoView(container.getContext());

photoView.setImageDrawable(mDrawable);

// 在ViewPager中添加PhotoView,并返回

container.addView(photoView, LayoutParams.MATCH_PARENT,

LayoutParams.MATCH_PARENT);

return photoView;

}


@Override

public void destroyItem(ViewGroup container, int position, Object object) {

container.removeView((View) object);

}

}


@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return false;

}


}


cc_美团 商品详情图片放大显示ViewPager

标签:图片放大viewpager

原文地址:http://1137907860.blog.51cto.com/10452906/1675212

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!