0

Please refer to this link My android application layout does not fit well on different devices? I have 9 rows in portrait mode and 7 in landscape mode.I was thinking to calculate height and width of screen before calling. setContentView(R.layout.main); Then calculate total height/9 for portrait mode and height/7 for landscape mode. Can anyone tell me how to proceed?That is how to know dynamically if layout is landscape or portrait , and how to assign height to rows.

Community
  • 1
  • 1
user3404195
  • 189
  • 11
  • What type of Layout are you using for your main.xml file? – kandroidj Mar 12 '14 at 15:19
  • scrollview tablelayout – user3404195 Mar 12 '14 at 15:28
  • Is this a must have layout or could a grid layout serve the same purpose? Do you have columns headers, etc. that require the table layout? – kandroidj Mar 12 '14 at 15:41
  • You might need to create a different layout for portrait and landscape views. I have done this a few times when the activity looks rubbish after being rotated. Have a look at this: http://stackoverflow.com/questions/2124046/how-do-i-specify-different-layouts-for-portrait-and-landscape-orientations – David Christopher Reynolds Mar 12 '14 at 15:43
  • I have different layouts for landscape and portrait.Is grid layout supported by android version 2.1 – user3404195 Mar 12 '14 at 15:51

1 Answers1

0

You can assign create two different layout with the same name and place them in the landscape and portrait folders respectively. Create a new folder called "layout-land" in the res folder and place the landscape version of the layout in there and the portrait version in the "layout" folder. Android will automatically take the appropriate layout based on your orientation. Note that both the landscape and portrait version of the layout must have the same name.

Also inside the code, you can determine the application's orientation

int orientation = getResources().getConfiguration().orientation
if(orientation == Configuration.ORIENTATION_LANDSCAPE)
//landscape code...
else
//portrait code...
Parnit
  • 1,032
  • 2
  • 8
  • 16
  • I have done that android detects the layout and every thing is well but the buttons do not take up all available pace. please check the question in the link. I foolishly asked a different question whereas i could just edit my question in link above. – user3404195 Mar 12 '14 at 15:58
  • int Orientation = getResources().getConfiguration().orientation; if(Orientation == Configuration.ORIENTATION_LANDSCAPE) { Set height of all rows. } This is what i want how can i set height for each row now. – user3404195 Mar 12 '14 at 16:10