ahmadmanga
ahmadmanga

Reputation: 29

change the size of frame and it's contents according to screen

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)

Upvotes: 0

Views: 2471

Answers (2)

Emil Pana
Emil Pana

Reputation: 478

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.

Upvotes: 0

Matt
Matt

Reputation: 3847

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)

Upvotes: 1

Related Questions