Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proportional width of elements in LinearLayout

I have a horizontal LinearLayout and in it I have EditText and Spinner elements. Which attributes I need to adjust so I would get proportional widths: I want EditText to take 3/5 and Spinner - 2/5 of all available width?

My code looks like this:

<LinearLayout 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:id="@+id/LinearLayout01">

    <EditText 
        android:layout_height="wrap_content" 
        android:id="@+id/EditText01" 
        android:singleLine="true">
    </EditText>

    <Spinner 
        android:layout_height="wrap_content" 
        android:id="@+id/Spinner01" 
        android:layout_width="wrap_content">
    </Spinner>

</LinearLayout>

I tried setting android:layout_weight, but somehow it does not look "stable" enough for me - when EditText has no text - everything looks fine, but as soon as I start entering text into it - it starts expanding and Spinner shrinking accordingly...

like image 762
Laimoncijus Avatar asked Jun 02 '10 19:06

Laimoncijus


2 Answers

To literally achieve your request, try setting both widgets' android:layout_width="0px", then set your android:layout_weight values as appropriate (3 and 2).

like image 52
CommonsWare Avatar answered Nov 11 '22 09:11

CommonsWare


Try setting the layout_width to 0dip as well as using layout_weight. That should do it.

like image 42
m6tt Avatar answered Nov 11 '22 08:11

m6tt