Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>Short version:</em></p> <p>clip_horizontal and clip_vertical apply to the measurements of the <em>view</em> itself, before any contents (such as the image in a BitmapDrawable) are rendered.</p> <hr> <p><em>Long version:</em></p> <p>I've run into some similar confusion over clip_horizontal and clip_vertical. (In my case, it was related to android:gravity for a BitmapDrawable, but it's similar enough to be applicable.)</p> <p>From the documentation I thought that something like android:gravity="top|left|clip_vertical" on a bitmap would cause the image's top left corner to be positioned at the view's top left corner, and that, if the bitmap was taller than the view, it would be "clipped" at the bottom edge of the view. In other words, show only as much of the bitmap that the view is tall enough to reveal; do not stretch the bitmap, but instead only show whatever will fit, letting the rest extend below the bottom edge.</p> <p>However, the opposite happened: when I set clip_vertical, a large bitmap was squished vertically to fit within the height of the view.</p> <p>After examining the applyDisplay() method in platform/frameworks/core/java/android/view/Gravity.java, I realized my mistake:</p> <p>It isn't the bitmap <em>image</em> that was going to be clipped, but the <em>view</em> -- the actual size of the container the image is ultimately rendered into.</p> <p>Setting clip_vertical in my case didn't mean "clip the image at the bottom edge," it meant "clip the BitmapDrawable's view itself so its height matches the height of its parent container"...which then caused the image to be "squished" as it filled that shorter height.</p> <p>So, the important thing to remember with android:gravity and android:layout_gravity is that clip_horizontal and clip_vertical apply to the measurements of the <em>view</em> itself, before any contents (such as my BitmapDrawable) are rendered.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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