0

How To maintain the aspect ratio of image like 3:4 show on portrait then this image should be convert 9:16 when move device in landscape and image should not be stretched. Hoe can maintain this please help me thanks advance.

My code are And this image i want to set on image switcher. How to maintain every image that is set on imageswicher should be aspect ratio.

public View makeView() {

        ImageView imageView = new ImageView(this);

        imageView.setAdjustViewBounds(true);
        WindowManager window = (WindowManager) getSystemService(Context.WINDOW_SERVICE);  
        Display display = window.getDefaultDisplay();

        imageView.setLayoutParams(new ImageSwitcher.LayoutParams(
                display.getWidth(), LayoutParams.FILL_PARENT));
        imageView.setBackgroundResource(R.drawable.border);
            imageView.setPadding(8, 8, 8, 8);
        imageView.setImageBitmap(image);
        imageView.setScaleType(ScaleType.FIT_XY);
}
Sunil Kumar
  • 7,086
  • 4
  • 32
  • 50
  • Hope this will help you ,, [See this][1] [1]: http://stackoverflow.com/questions/8232608/fit-image-into-imageview-keep-aspect-ratio-and-then-resize-imageview-to-image-d – Mit Bhatt Jun 07 '13 at 06:25

2 Answers2

0

ScaleType.FIT_XY does not preserve aspect ratio. It's not for photos, but usefull for decorative images. Try ScaleType.CENTER_CROP - your image will cropped to fit view bounds, or ScaleType.CENTER_INSIDE - your image will scaled to fit view bounds maintain the image's aspect ratio.

0

Instead of using:

    imageView.setBackgroundResource(R.drawable.border);

Use :

    imageView.setImageResource(R.drawable.border);

Also see this answer.

Community
  • 1
  • 1
Ami
  • 1