A (175)

(Tuis.) #1
CHAPTER 15: Developing for Android Wearable Devices 581

The XML markup for the final UI widget structure for a planet Earth icon should look
like this:


<ImageView android:id="@+id/earthIcon" android:contentDescription="@string/earthClock"
android:layout_margin="6dip" android:layout_gravity="bottom|right"
android:src="@drawable/earthbutton"
android:layout_width="wrap_content" android:layout_height="wrap_content" />


Notice that this time you need to use the “bottom|right” constant pairing inside of your
android:layout_gravity parameter, because the default “top” and “left” parameters both need to
be overridden to place the final planet icon into the bottom-right corner of the UI design. Also note
that this is a perfect design for a memory-efficient FrameLayout container class, because you can
use its basic layout_gravity and layout_margin parameter options to position this symmetrical
smartwatch UI design, and it only uses around 16 lines of XML mark-up. See Figure 15-35.


Remember that the FrameLayout container inherits its margin and padding options from the View
and ViewGroup superclasses, plus it has the android:layout_gravity parameter and its constants,
which you learned about in Chapter 11.


Now use the Graphical Layout Editor tab to preview your final UI design, as shown in Figure 15-36.
As you can see, you now have finger-tip-sized planet icons perfectly centered in your “available
white space” corner areas.


Figure 15-36. Use the Graphical Layout Editor to preview the earthIcon UI element’s placement

Free download pdf