Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to create this simple layout?

Tags:

android

layout

I need to create a simple layout with two form widgets (for example - two buttons). The first one must fill all available width of the parent layout and the second one must have some fixed size.

That's what I need: enter image description here

If I set FILL_PARENT to the first widget - I don't see the second one. It just blows away from a view area of the layout :) I don't know how to fix this...

like image 362
JavaRunner Avatar asked Oct 27 '12 00:10

JavaRunner


1 Answers

The easiest way to do this is using layout_weight with LinearLayout. Notice the width of the first TextView is "0dp", which means "ignore me and use the weight". The weight can be any number; since it's the only weighted view, it will expand to fill 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>
like image 188
Geobits Avatar answered Oct 13 '22 05:10

Geobits