Flexible Horizontal Layout with `layout_weight` and `maxWidth`
<p>I have a <code>TextView</code> and a square <code>ImageView</code> that I would like to show in a horizontal linear layout. Each should take half of the parent view's width and the height should fit the content (i.e. the image). The text should be centered vertically.</p>

<p>Additional constraint is that the image should not grow beyond a given <code>maxWidth</code> (= <code>maxHeight</code>), and excess width should be made available to the <code>TextView</code>. Obviously, this conflicts with the 50/50 rule above. Is there a way to prioritize the constraints, i.e. allow the image to take half of the space unless it exceeds a given size?</p>

<p><a href="https://i.stack.imgur.com/ikqUa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ikqUa.png" alt="desired outcome"></a></p>

<p><strong>These are layouts I tried:</strong> </p>

<p>The first one nicely stretches the left side to the available space. But the image takes more than half of the width as its <code>layout_weight</code> is not specified (as in image below).</p>

<pre><code>&lt;LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"&gt;

    &lt;LinearLayout
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center_vertical"&gt;
        &lt;TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Some text."/&gt;
    &lt;/LinearLayout&gt;

    &lt;ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxWidth="200dp"
        android:adjustViewBounds="true"
        android:src="@drawable/image" /&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p><a href="https://i.stack.imgur.com/pL2yH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pL2yH.png" alt="without &lt;code&gt;layout_weight&lt;/code&gt;"></a></p>

<p>When I add <code>layout_weight</code> to the <code>ImageView</code> it always takes half of the width and ignore the <code>maxWidth</code> (see image below).</p>

<pre><code>    &lt;ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:maxWidth="200dp"
        android:adjustViewBounds="true"
        android:src="@drawable/image" /&gt;
</code></pre>

<p><a href="https://i.stack.imgur.com/vrNtE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vrNtE.png" alt="with &lt;code&gt;layout_weight&lt;/code&gt;"></a></p>

<p>Enclosing the <code>ImageView</code> in another <code>LinearLayout</code> enables the <code>maxWidth</code> again, but the enclosing <code>LinearLayout</code> still takes half of the available space (see image below).</p>

<pre><code>    &lt;LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="right"&gt;

        &lt;ImageView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:maxWidth="200dp"
            android:adjustViewBounds="true"
            android:src="@drawable/image" /&gt;
    &lt;/LinearLayout&gt;
</code></pre>

<p><a href="https://i.stack.imgur.com/OeLlb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OeLlb.png" alt="using enclosing &lt;code&gt;LinearLayout&lt;/code&gt;"></a></p>

<p>Another option I have found for <a href="https://stackoverflow.com/a/6285192/3386180">similar scenarios</a> is to use a <code>RelativeLayout</code> with an invisible view as a center divider, but that locks the division to 50/50 (or wherever the divider is placed).</p>