Android ViewPager

ViewPagerjava

使用範圍:導航、菜單android

功能:可使視圖滑動,相似於Lanucher左右滑動數組

須要配置器PagerAdapter佈局

參考文獻:http://blog.csdn.net/alangdangjia/article/details/9054921this

實現步驟:3步spa

1.向佈局文件中添加android.support.v4.view.ViewPager組件.net

  這個組件,注意這個組件是用來顯示左右滑動的界面的,若是不加載xml佈局文件,他是不會顯示內容的。code

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

2.加載顯示頁卡xml

LayoutInflater lf = getLayoutInflater().from(this);
	view1 = lf.inflate(R.layout.layout1, null);
	view2 = lf.inflate(R.layout.layout2, null);
	view3 = lf.inflate(R.layout.layout3, null);

	// 將要分頁顯示的View裝入數組中
	List<View> viewList = new ArrayList<View>();
	viewList.add(view1);
	viewList.add(view2);
	viewList.add(view3);


3.在activity中實例化ViewPager組件,重寫PageAdapter與ListAdapter相似。對象

  重寫方法有兩種:建立PagesAdapter對象,從新建立類繼承PageAdapter。

  其中必須覆蓋如下方法:

instantiateItem(ViewGroup, int)
	destroyItem(ViewGroup, int, Object)
	getCount()
	isViewFromObject(View, Object)
相關文章
相關標籤/搜索