Created
December 30, 2016 06:32
-
-
Save manishkpr/c4cbcf49adec02123ca7c990cbbc6159 to your computer and use it in GitHub Desktop.
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 ImageAdapter extends PagerAdapter { | |
Context context; | |
private int[] GalImages = new int[] { | |
R.drawable.one, | |
R.drawable.two, | |
R.drawable.three | |
}; | |
ImageAdapter(Context context){ | |
this.context=context; | |
} | |
@Override | |
public int getCount() { | |
return GalImages.length; | |
} | |
@Override | |
public boolean isViewFromObject(View view, Object object) { | |
return view == ((ImageView) object); | |
} | |
@Override | |
public Object instantiateItem(ViewGroup container, int position) { | |
ImageView imageView = new ImageView(context); | |
int padding = context.getResources().getDimensionPixelSize(R.dimen.padding_medium); | |
imageView.setPadding(padding, padding, padding, padding); | |
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); | |
imageView.setImageResource(GalImages[position]); | |
((ViewPager) container).addView(imageView, 0); | |
return imageView; | |
} | |
@Override | |
public void destroyItem(ViewGroup container, int position, Object object) { | |
((ViewPager) container).removeView((ImageView) object); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment