Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe the <code>android:gravity</code> attributes you are looking for are <code>clip_vertical</code> and <code>clip_horizontal</code>, but a word of advice. These attributes may not behave the way you think they should. You cannot use them to clip an image in both directions, only one. The following code:</p> <pre><code>&lt;bitmap android:src="@drawable/background" android:gravity="clip_vertical|clip_horizontal" /&gt; </code></pre> <p>does not allow the image to be cropped in both directions...it actually fits the image inside the view as if you had not set either one. It also can be confusing that setting a clip parameter essentially sets that direction to fit the view, with the other direction being cropped out. A few examples:</p> <pre><code>&lt;!-- Force fit top/bottom, crop left/right with image centered --&gt; &lt;bitmap android:src="@drawable/background" android:gravity="clip_vertical" /&gt; &lt;!-- Force fit top/bottom, align image left and crop right edge --&gt; &lt;bitmap android:src="@drawable/background" android:gravity="left|clip_vertical" /&gt; &lt;!-- Force fit left/right, crop top/bottom with image centered --&gt; &lt;bitmap android:src="@drawable/background" android:gravity="clip_horizontal" /&gt; &lt;!-- Force fit left/right, align top and crop bottom egde --&gt; &lt;bitmap android:src="@drawable/background" android:gravity="top|clip_horizontal" /&gt; </code></pre> <p>Notice that these settings allow an image larger than the view to be cropped, but if the image is smaller than the view, its contents will still be stretched to fit. In order to govern how an image will behave in a <code>&lt;bitmap&gt;</code> tag when it is smaller than the view, look at <code>tileMode</code>. Note that <code>tileMode</code> and <code>gravity</code> cannot be used together; <code>gravity</code> will be ignored if both are included.</p> <p>If you need more dynamic control of how the image scales in addition to this, and you do not want to use an <code>ImageView</code>, you could also wrap the resulting Drawable in a <code>ScaleDrawable</code> and configure the x/y scale percentages in Java code based on the measured view sizes.</p>
    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.
    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