0

Is there any way to auto fit the screen when changing the orientation?

Because when I view my App in Portrait mode all the images seems fined but when I change it into Landscape the images becomes pix-elated or has been stretched to much. So I'm wondering if there is auto fit screen.

thanks for any thoughts.

Anders Metnik
  • 6,096
  • 7
  • 40
  • 79
Gangnaminmo Ako
  • 577
  • 11
  • 28

5 Answers5

3

Specify different layouts with same name in layout-land folder and use suitable drawables. For more help see this tutorial

http://www.androidpeople.com/android-portrait-amp-landscape-differeent-layouts

Tahreem
  • 205
  • 5
  • 15
  • how can I check if the Orientation has been changed? – Gangnaminmo Ako Nov 28 '12 at 09:35
  • if you do this way, then OS will automatically render the layout according to orientation – Tahreem Nov 28 '12 at 12:11
  • 1
    Btw this is how u can get Orientation at run time: Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); int orientation = display.getOrientation(); – Tahreem Nov 28 '12 at 12:13
1
Display display;
int width;
int height;

in onCreate() add width = display.getWidth(); height = display.getHeight();

in onResume() add

if(width<height){
 //you can add your layout here (landscape)
}else{
    //you can add your layout here (portrait)
}
kumar
  • 691
  • 1
  • 7
  • 16
0

you must have two layouts, one for portrait and another for landscape orientation. You can use the same images if you use two layouts.

kumar
  • 691
  • 1
  • 7
  • 16
0

There are two possibilities,

Option 1 : You can have different XML layouts in layout-port ,layout-land,drawable,drawable-land. In those XML layouts, you can fix different sized images that matches your screen density.For different set of images, you can review on ldpi,mdpi,hdpi,xhdpi.

Option 2 : You can go with Nine patch images.

If you find a better solution,Share it.

Cheers.

Nandagopal T
  • 2,037
  • 9
  • 42
  • 54
0

You can use following snippet to recognize the configuration has been changed

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

 // Checks the orientation of the screen and do your action here

}

Cheers.

Nandagopal T
  • 2,037
  • 9
  • 42
  • 54