0

let's say I have Frame-layout with:

width = 200dp;
height = 100dp;

I want the frame width to adapt to screen "width" and get the "Aspect ratio" and change the "height" according to it so I can do the same to it's content.

whats the best way to do that? I searched but didn't find an answer.

(if it helps the Frame is centered)

Cœur
  • 37,241
  • 25
  • 195
  • 267
ahmadmanga
  • 29
  • 1
  • 10
  • What do you want to achieve and how did you try to achieve this until now ? – Emil Pana Jun 24 '13 at 17:08
  • I try to do "the scree" in (up a little to) the center of screen, and a button down it. I found a way but the frame layout and it's contents change by screen size ... so I need to get the "aspect ratio" to stay the same on almost any screen. – ahmadmanga Jun 24 '13 at 17:37

2 Answers2

1

There's a good post about getting screen size here:

https://stackoverflow.com/a/1016941/356708

Once you have that, you can manually set the size of your layout. This post shows some details about that:

https://stackoverflow.com/a/11911123/356708

You can probably use pixels across-the-board, but not knowing what exactly you're doing, you might want to stick with something like DIP (example at same link)

Community
  • 1
  • 1
Matt
  • 3,837
  • 26
  • 29
0

I personally do not recommend the use of FrameLayout, especially if you have more that one child in it.

You should use LinearLayout and provide its childs a weight to maintain their ratio. I do not think that you need to do that programmatically, that's why I recommend the use of LinearLayout.

Emil Pana
  • 468
  • 5
  • 14