2

I'm stuck on something that is probably simple but I just can't seem to figure it out. An example of what I'm looking for is a screen with 4 buttons. One taking the entire top left quadrant, the 2nd taking the entire top right quadrant, the 3rd taking the entire bottom left quadrant and the 4th taking the entire bottom right quadrant. The end result would be that the 4 buttons fill the entire screen.

I seem to be able to equally stretch objects to fill the width of the screen or I can stretch objects to fill the height. What I can't seem to figure out is how to stretch the width and height at the same time.

Any help with this would be greatly appreciated.

1 Answer 1

3

I imagine you're trying to do this with one LinearLayout. I would probably just use two LinearLayouts to handle it. Something like:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1"> <Button android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="1" /> <Button android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="1" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1"> <Button android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="1" /> <Button android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="1" /> </LinearLayout> </LinearLayout> 

Just tested that and it definitely works. LINT says nesting weights is bad for performance, but it definitely has the right layout.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.