Android: How to create this simple layout?

I need to create a simple layout with two prominent widgets (for example, two buttons). The first should fill the entire available width of the parent layout, and the second should have a fixed size.

What I need: enter image description here

If I set FILL_PARENT for the first widget - I do not see the second. It just resets from the view area of ​​the layout :) I don’t know how to fix it ...

+6
source share
2 answers

The easiest way to do this is to use layout_weight with LinearLayout . Note that the width of the first TextView is "0dp" , which means "ignore me and use weight." Weight can be any number; since it is the only balanced species, it will expand to fill the available space.

 <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /> <TextView android:layout_width="25dp" android:layout_height="wrap_content" /> </LinearLayout> 
+14
source

You can accomplish this using RelativeLayout or FrameLayout.

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_marginBottom="5dp" android:layout_marginTop="5dp" android:layout_marginLeft="5dp" android:background="#ccccee" android:text="A label. I need to fill all available width." /> <TextView android:layout_width="20dp" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginBottom="5dp" android:layout_marginTop="5dp" android:paddingRight="5dp" android:background="#aaddee" android:text=">>" /> </RelativeLayout> 

How the layout looks

+1
source

All Articles