Skip to content

Instantly share code, notes, and snippets.

@IvBaranov
Last active June 11, 2019 19:44
Show Gist options
  • Save IvBaranov/264054ef13222165c3273e92d7b84a4e to your computer and use it in GitHub Desktop.
Save IvBaranov/264054ef13222165c3273e92d7b84a4e to your computer and use it in GitHub Desktop.
Android quick image fullscreen slider
public class AndroidImageAdapter extends PagerAdapter {
Context mContext;
AndroidImageAdapter(Context context) {
this.mContext = context;
}
@Override
public int getCount() {
return sliderImagesId.length;
}
private int[] sliderImagesId = new int[]{
R.drawable.image_1, R.drawable.image_2, R.drawable.image_3
};
@Override
public boolean isViewFromObject(View v, Object obj) {
return v == ((ImageView) obj);
}
@Override
public Object instantiateItem(ViewGroup container, int i) {
ImageView mImageView = new ImageView(mContext);
mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
mImageView.setImageResource(sliderImagesId[i]);
((ViewPager) container).addView(mImageView, 0);
return mImageView;
}
@Override
public void destroyItem(ViewGroup container, int i, Object obj) {
((ViewPager) container).removeView((ImageView) obj);
}
}
//...
AndroidImageAdapter adapterView = new AndroidImageAdapter(this);
pager.setAdapter(adapterView);
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment