use of com.bm.library.PhotoView in project PhotoView by bm-x.
the class ViewPagerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_pager);
mPager = (ViewPager) findViewById(R.id.pager);
mPager.setPageMargin((int) (getResources().getDisplayMetrics().density * 15));
mPager.setAdapter(new PagerAdapter() {
@Override
public int getCount() {
return imgsId.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
PhotoView view = new PhotoView(ViewPagerActivity.this);
view.enable();
view.setScaleType(ImageView.ScaleType.FIT_CENTER);
view.setImageResource(imgsId[position]);
container.addView(view);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
});
}
use of com.bm.library.PhotoView in project PhotoView by bm-x.
the class PhotoBrowse method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_photo_browse);
in.setDuration(300);
out.setDuration(300);
out.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
mBg.setVisibility(View.INVISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
mParent = findViewById(R.id.parent);
mBg = findViewById(R.id.bg);
mPhotoView = (PhotoView) findViewById(R.id.img);
mPhotoView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
gv = (GridView) findViewById(R.id.gv);
gv.setAdapter(new BaseAdapter() {
@Override
public int getCount() {
return imgs.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
PhotoView p = new PhotoView(PhotoBrowse.this);
p.setLayoutParams(new AbsListView.LayoutParams((int) (getResources().getDisplayMetrics().density * 100), (int) (getResources().getDisplayMetrics().density * 100)));
p.setScaleType(ImageView.ScaleType.CENTER_CROP);
p.setImageResource(imgs[position]);
// 把PhotoView当普通的控件把触摸功能关掉
p.disenable();
return p;
}
});
gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
PhotoView p = (PhotoView) view;
mInfo = p.getInfo();
mPhotoView.setImageResource(imgs[position]);
mBg.startAnimation(in);
mBg.setVisibility(View.VISIBLE);
mParent.setVisibility(View.VISIBLE);
;
mPhotoView.animaFrom(mInfo);
}
});
mPhotoView.enable();
mPhotoView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mBg.startAnimation(out);
mPhotoView.animaTo(mInfo, new Runnable() {
@Override
public void run() {
mParent.setVisibility(View.GONE);
}
});
}
});
}
Aggregations