Note that there are some explanatory texts on larger screens.

plurals
  1. PONearly-wrapping TextView is clipping ImageView in LinearLayout
    primarykey
    data
    text
    <p>I have a horizontal LinearLayout set to wrap_content. Inside is a vertical LinearLayout containing a single TextView that allows multiple lines (also wrap_content) and an ImageButton (wrap_content). Several of the components have margins and padding so things space out nicely. </p> <p>When the text in the TextView is short, everything is fine. When the text wraps to multiple lines, still fine. When the text is <em>almost</em> long enough to wrap, the ImageButton gets clipped horizontally - its left and right sides are lopped off. If I pull out the margins and padding it works, but of course it doesn't look good.</p> <p>My guess is that the layout system is calculating the text width without taking into account some of the margins and padding. Then it's laying things out, and there's less total space than that first pass at the TextView thought, so it's clipping the second item in the layout and honoring the calculated TextView width. But that is just a guess.</p> <p>Short of writing my own layout, any ideas?</p> <p><strong>EDIT</strong></p> <p>Here's a screen shot from hierarchy viewer, showing where the ImageButton is clipped and with the relevant XML highlighted. The ImageButton's bounds are consistent with what I'm seeing: 27dp wide, whereas the circle image itself is actually 36dp wide, and the ImageButton has 4dp padding specified on each side. </p> <p><img src="https://i.stack.imgur.com/hymrd.png" alt="Screen shot of hierarchy viewer"></p> <p>Again, I had to choose that text carefully: any shorter and the button is fine; longer and it would wrap, and the button's fine again.</p> <p><strong>EDIT</strong></p> <p>And, here's my XML:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/messageBubble" android:layout_width="wrap_content" android:layout_height="match_parent" android:minHeight="@dimen/message_bubble_min_height" android:layout_alignTop="@id/avatar" android:layout_alignLeft="@id/avatar" android:layout_marginTop="@dimen/message_bubble_margin_top" android:layout_marginLeft="@dimen/message_bubble_inset" android:layout_marginRight="@dimen/message_inbound_padding_inside" android:paddingLeft="@dimen/message_bubble_padding_outside" android:paddingRight="@dimen/message_bubble_padding_inside" android:paddingTop="@dimen/message_bubble_padding_v" android:paddingBottom="@dimen/message_bubble_padding_v" android:orientation="horizontal"&gt; &lt;LinearLayout android:id="@+id/contentContainer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:orientation="vertical"&gt; &lt;TextView android:id="@+id/messageBody" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/message_body_margin_outside" android:layout_marginRight="@dimen/message_body_margin_inside" android:layout_marginTop="@dimen/message_body_margin_v" android:layout_marginBottom="@dimen/message_body_margin_v" android:gravity="left" android:autoLink="all" android:textSize="17dp" /&gt; &lt;/LinearLayout&gt; &lt;include layout="@layout/view_message_action_btn" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>And the included view_message_action_btn:</p> <pre><code>&lt;ImageButton xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/actionButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:src="@drawable/action_btn" android:paddingLeft="@dimen/message_action_btn_padding_h" android:paddingRight="@dimen/message_action_btn_padding_h" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload