A (175)

(Tuis.) #1

364 CHAPTER 10: Android Animation: Making Your UI Designs Move


You will need to add in a parameter that tells Android not to scale our referenced drawable
assets, but instead to “respect” their pixel dimensions and draw them “pixel-for-pixel.” The
android:adjustViewBounds="true" will perform this function for the UI widget, as you
can see in the center pane of Figure 10-5. If you want to see the markup for this in the ,
take a look at Figure 10-6.


Figure 10-6. Add adjustViewBounds=“true” and 40 DIP of android:padding value to shrink the source and center


Resizing Source Imagery: Using Padding Values


As you can see in the middle and right panes of Figure 1 0- 5 , the foreground and background
image plates in the ImageView are now conforming the ImageView to the pixel dimensions of these
images, except that the UI widget is still scaling up the source image to match the dimensions
of the background image. We’ll need another parameter to be able to get around this problem.
Hopefully one day, Android OS developers will add in the android:maintainDrawablePixels
parameter which, when set to true, will allow developers to do their relative pixel scale compositing
(that is, different layers with different pixel dimensions, as we are using here) outside of the Android
OS. For now, we are going to leverage the android:padding parameter, which installs space on the
inside of the View container; in this case, it is an ImageView. An android:layout_margin parameter,
on the other hand, installs space on the outside of the View container, which moves the entire
container around on the screen. Padding, on the other hand, scales what is inside of that container.
We’ll use this to our advantage in order to fine-tune the effect of the ring background around the
outside of our animation.


Fortunately, the android:padding parameter only affects the source (foreground) image plate, which
in this case, is referencing the anim_milkyway XML animation asset that we have recently created,
using .


We are going to use this fact that padding only scales (affects) the foreground image plate to our
advantage, by adding an android:padding parameter, which will add the same amount of padding on
all four sides (insides) of the ImageView container. This will serve to both scale down (technically this
would be called downsampling) and center the Lunar Lander animation, allowing the background
plate ring decoration element to show through from its lower z-order location (on the compositing
layer underneath the foreground image).

Free download pdf