Last active
June 11, 2019 19:44
-
-
Save IvBaranov/264054ef13222165c3273e92d7b84a4e to your computer and use it in GitHub Desktop.
Android quick image fullscreen slider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
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