Note that there are some explanatory texts on larger screens.

plurals
  1. POTiled background is pushing it's View size
    primarykey
    data
    text
    <p>I have a tiled bitmap that I'm using as the <code>View</code> background. This <code>View</code>, let's say, has <code>android:layout_height="wrap_content"</code>. The problem is that the height of the bitmap used in the background is participating in the measurement of the view, increasing the <code>View</code> height. This can be noticed when the size of the content of <code>View</code> is smaller than the height of the bitmap used as the tile background. </p> <p>Let me show you an example. The tile bitmap:</p> <p><img src="https://i.stack.imgur.com/GnU5z.jpg" alt="enter image description here"></p> <p>The bitmap drawable (<code>tile_bg.xml</code>):</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/tile" android:tileMode="repeat"/&gt; </code></pre> <p>The layout:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="#FFFFFF"&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/tile_bg" android:text="@string/hello" android:textColor="#000000" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>How it looks like:</p> <p><img src="https://i.stack.imgur.com/fA9Hp.png" alt="enter image description here"></p> <p>The height of the <code>TextView</code> ends up being the height of the bitmap. What I was expecting is that the bitmap gets clipped to the size of the <code>View</code>. </p> <p>Is there any way to achieve this?</p> <p>Notes: </p> <ul> <li>I can't use 9patch drawables since the background needs to be repeated in a tile fashion way, stretching is not an option.</li> <li>I can't set a fixed height for the <code>View</code>, it depends of the children (I'm using this in a <code>ViewGroup</code>)</li> <li>This odd behavior happens as I explained before when the size of the <code>View</code> is smaller than the size of the bitmap, otherwise the bitmap is repeated an clipped correctly (ie, if the view size is 1.5x the size of the bitmap, you end up seeing 1.5 times the bitmap).</li> <li>The example deals with the height, but is the same using the width.</li> </ul>
    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.
 

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