forum

Home / DeveloperSection / Forums / Android LinearLayout horizontally or vertically oriented items fill remaining space

Android LinearLayout horizontally or vertically oriented items fill remaining space

Anonymous User 2030 18-Nov-2014

I wonder if it is possible to have two items in a LinearLayout one wraps its content and the other fills the remaining horizontal space. I do this frequently in WPF (.NET) by specifying HorizontalAlignment="Stretch".

For example:

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="24dp"
    android:background="#0000FF"/>
<ImageView
    android:layout_width="match_parent"
    android:layout_height="24dp"
    android:background="#FF0000"/>

When I do this the second ImageView fill the whole horizontal space as I expected. I tried to set both wrap_content and use gravity such as android:gravity="start" and android:gravity="fill_horizontal" for the second one it did not worked.

NOTE: I can achieve something similar by specifying weight attribute. But this is providing a division according to the percent value. This is not I want.


Updated on 19-Nov-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By