January 2013
Intermediate to advanced
408 pages
9h 23m
English
The FrameLayout is a placeholder on screen that you can use to display a single view. Views that you add to a FrameLayout are always anchored to the top left of the layout. This recipe shows how to use the FrameLayout to create a simple image viewer.
For this recipe, assume you have three images located in the res/drawable-mdpi folder (see Figure 2-22).
You also need to add the following code snippet in the activity_main.xml file:
<RelativeLayout android:id="@+id/RLayout" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <TextView android:id="@+id/lblComments" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, Android!" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" /> <FrameLayout android:id="@+id/framelayout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/lblComments" android:layout_below="@+id/lblComments" android:layout_centerHorizontal="true" > <ImageView android:src = "@drawable/galaxy_s3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:tag="1" ...Read now
Unlock full access