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!


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="" xmlns:custom="" xmlns:tools="" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:background="@drawable/background_blue" android:orientation="vertical"> < android:id="@+id/pager"


This is Yahya Christian School Magazine

Read more
Read more
Similar to
Popular now
Just for you