Page 142

Android Programming Cookbook

134 / 143

Figure 8.4: Add an activity to Mobile. Choose: Add no activity. Now, our project has just been created!

8.2

Create the layout of the main AndroidViewPagerExample

The AndroidViewPagerExample is the main Activity of our example, and this is the Activity in which we are going to create a ViewPager instance and set its FragmentPagerAdapter. Now, we are going to make the layout of this Activity, which will be a simple layout xml for the AndroidViewPagerExample.class, that consists of a LinearLayout with vertical orientation, that includes a ViewPager. Add a new xml file inside /res/layout folder, with name activity_main.xml. We should have the /res/layout/activi ty_main.xml file and paste the code below. activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="https://schemas.android.com/apk/res/android" xmlns:custom="https://schemas.android.com/apk/res-auto" xmlns:tools="https://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:background="@drawable/background_blue" android:orientation="vertical"> <android.support.v4.view.ViewPager android:id="@+id/pager"

SKY MAGZ  

This is Yahya Christian School Magazine

Read more
Read more
Similar to
Popular now
Just for you