A (175)

(Tuis.) #1
CHAPTER 11: Digital Video: Streaming Video, MediaPlayer, and MediaController classes 437

This will center the widget inside of the container. You can see the
centering result on the right-hand side of Figure 11-30.


Scaling Video Non-Uniformly to Fit the Screen


Let’s see if there is any method that we can use to force Android to scale our video to fit the display
screen. We know that a container won’t allow us to do this, so which of Android’s
layout container classes which we have learned about so far would allow this? The
container has layout_alignParent parameters, might we use those to “force” Android OS to scale
this video non-uniformly, without respect to aspect ratio? Let’s try it and see!


Change the and opening and closing parent tags to


and , respectively, and remove the android:layout_gravity
parameter and replace it with all four of the layout_alignParent parameters, using the following XML
markup, as shown in Figure 11-32:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent" >
<VideoView android:id="@+id/videoPlayer"
android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_alignParentLeft="true" android:layout_alignParentRight="true"
android:layout_alignParentTop="true" android:layout_alignParentBottom="true" />



Figure 11-31. Add an android:layout_gravity parameter to the tag configured with a center constant

Free download pdf