Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
The property
android:layout_gravity="clip_vertical|horizontal"
does the following as mentioned in the
SDK
documentation:
Additional option that can be set to
have the top and/or bottom edges of
the child clipped to its container's
bounds. The clip will be based on the
vertical gravity: a top gravity will
clip the bottom edge, a bottom gravity
will clip the top edge, and neither
will clip both edges.
But I can't see anything of this in my applications,
so what is the purpose of this property exactly ?
thanks
Long version:
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.)
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.
However, the opposite happened: when I set clip_vertical, a large bitmap was squished vertically to fit within the height of the view.
After examining the applyDisplay() method in platform/frameworks/core/java/android/view/Gravity.java, I realized my mistake:
It isn't the bitmap
image
that was going to be clipped, but the
view
-- the actual size of the container the image is ultimately rendered into.
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.
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
view
itself, before any contents (such as my BitmapDrawable) are rendered.
–
–
–
Thanks for contributing an answer to Stack Overflow!
-
Please be sure to
answer the question
. Provide details and share your research!
But
avoid
…
-
Asking for help, clarification, or responding to other answers.
-
Making statements based on opinion; back them up with references or personal experience.
To learn more, see our
tips on writing great answers
.