0

I have images inside ViewPager. I have read that we cant set Wrap_CONTENT as height of ViewPager as it wont work. So what should I do to diplay images in proper aspect ratio as the images size may vary. So what can I do to achieve this.

Suggestions please.

Vaibs
  • 1,128
  • 3
  • 16
  • 36

1 Answers1

0

You need to use view.setImageResource instead of view.setBackgroundResource, the properties you apply are not getting set on the "Background"

@Override
public Object instantiateItem(View container, int position) {
    ImageView view = new ImageView(activity);
    view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
    view.setAdjustViewBounds(true);
    view.setScaleType(ScaleType.FIT_CENTER);
    view.setImageResource(imageArray[position]);
    ((ViewPager) container).addView(view, 0);
    return view;
}
maxi.patti
  • 61
  • 3