0

I am very new to relative layouts and Android Studios overall and after a while of effort I got the view looking the way I want, however I cannot figure out how to make buttons resize with the view and keep their aspect ratio in a relative layout. The width and heights of the four buttons are set to wrap_content, setting it to match parent makes them resize, however they take up the whole screen so does anyone know how i can get the buttons to resize to the screen used and also keep the aspect ratio of it? I have tried to find an answer and I can't. Any solutions are greatly appreciated thank you!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
New Guy
  • 39
  • 8

2 Answers2

1

Use dp. For example, android:layout_width="50dp". dp is something like universal measument unit, you could think of it as percentage. Different screens can have same dp, ussually it's 320 (I think) and when you say you want something to be wide 50 dp, it will take about 15% of the screen, on ANY screen with same maximum dp.

Or you can use different layouts for different screen sizes.

Here is the long answer: https://developer.android.com/guide/practices/screens_support.html

leonz
  • 1,107
  • 2
  • 10
  • 32
0

Use a linear layout with layout weight as 4 (as you have 4 buttons) I am assuming you are talking about taking up the whole width of the screen. Set the weight of each button as 1 so the overall weight becomes 4 which is equal to the linear layout weight and make sure you set the width of each button as 0dp as the weight will take care of the width of each button. Use this link as reference. I hope to have solved your problem.

Community
  • 1
  • 1
PunK _l_ RuLz
  • 621
  • 6
  • 20