---
title: "Android LinearLayout horizontally or vertically oriented items fill remaining space"  
description: "Android LinearLayout horizontally or vertically oriented items fill remaining space"  
author: "Anonymous User"  
published: 2014-11-18  
updated: 2014-11-19  
canonical: https://www.mindstick.com/forum/12635/android-linearlayout-horizontally-or-vertically-oriented-items-fill-remaining-space  
category: "android"  
tags: ["android layout"]  
reading_time: 1 minute  

---

# Android LinearLayout horizontally or vertically oriented items fill remaining space

I [wonder](https://yourviews.mindstick.com/story/2441/wheatgrass-juice-wonder-for-your-health) if it is possible to have two [items](https://www.mindstick.com/forum/33812/getting-number-of-items-selected-in-uicollectionview-in-ios) in a LinearLayout one wraps its [content](https://www.mindstick.com/articles/13019/get-the-best-content-marketing-pricing-packages-for-your-brand) and the other fills the remaining horizontal [space](https://www.mindstick.com/articles/12954/do-your-electrical-repair-in-your-own-space). I do this frequently in [WPF](https://www.mindstick.com/forum/304/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](https://answers.mindstick.com/qa/41761/how-did-the-second-industrial-revolution-influence-women-s-roles-in-society) [ImageView](https://www.mindstick.com/forum/34664/how-to-set-an-image-on-imageview-in-android) fill the whole horizontal space as I expected. I tried to set both wrap_content and use gravity such as [android](https://www.mindstick.com/articles/13046/10-reasons-why-i-prefer-android-vs-iphone-ios):gravity="start" and android:gravity="fill_horizontal" for the second one it did not worked.

NOTE: I can achieve something similar by specifying [weight](https://www.mindstick.com/articles/12951/the-importance-of-breakfast-in-weight-reduction) attribute. But this is providing a division according to the percent value. This is not I want.

## Replies

### Reply by David Miller

You can do this using the weight attribute itself. Try the following method

```
<ImageView    android:layout_width="wrap_content"    android:layout_height="24dp"    android:background="#0000FF"/><ImageView    android:layout_width="0dp"    android:layout_height="24dp"    android:layout_weight="1"    android:background="#FF0000"/>
```

include this in your horizontal linear layout


---

Original Source: https://www.mindstick.com/forum/12635/android-linearlayout-horizontally-or-vertically-oriented-items-fill-remaining-space

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
