Using ViewPager for Android Dev

current situation

Field of use

Most of apps will use viewpager in different format, even a very simple app. For example, the [wechat](https://play.google.com/store/apps/details?id=com.tencent.mm&hl=zh_CN). It only has for main content pages, but it uses viewpager. Our system app, luncher, uses viewpager as well. 

Formats of ViewPager

The main format is that a container wrapping many pages shown horizonally. It can be used show ad pictures, and also can be used show many fragments. In many situations, the other indicators will be used with it.

Analysis of ViewPager

Source Code

ViewPager is type of ViewGroup, so that it has all features of ViewGroup.

ViewPager shows data by the PageAdpter. It means that viewpager likes ListView showing data by adapter pattern.

The main feature of ViewPager unlike others views is its TouchEvent function. It intercept the touch events and translates them to the operation on its pages, such as scroll left or right, etc.

Use of ViewPager

Using ViewPager by declaring in the layout file, as follows:

<android.support.v4.view.ViewPager  
    android:id="@+id/viewpager"  
    android:layout_width="wrap_content"
    android:layout_height="200dip"  
    android:layout_gravity="center">  

    <android.support.v4.view.PagerTitleStrip  
        android:id="@+id/pagertitle"    
        android:layout_width="wrap_content"    
        android:layout_height="wrap_content"    
        android:layout_gravity="top"  
        />  

</android.support.v4.view.ViewPager> 

Of course, you can replace the PageTitleStrip by other indicators. You just need change the PageChangeListener for viewpager.