Android: how to make a view grow to fill available space?

If you want to keep the layout the same (ie, buttons after the text), use the layout_weight property, along with fill_parent, thus:

<LinearLayout 
    android:orientation="horizontal"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content">
    <EditText 
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </EditText>
    <ImageButton 
        android:src="https://stackoverflow.com/questions/5406092/@drawable/img1"
        android:layout_width="50dip" 
        android:layout_height="50dip">
    </ImageButton>
    <ImageButton 
        android:src="@drawable/img2"
        android:layout_width="50dip" 
        android:layout_height="50dip">
    </ImageButton>
 </LinearLayout>

Giving the EditText ‘weight’ makes it get figured out last and gives precedence to the buttons. Play with the different layout_weights and see how much fun you can have!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)