viewPager:
- public method:
-
setCurrentItem(int item)/setCurrentItem(int item,boolean smoothScroll)
: 設(shè)置選擇的頁面
set the currently selected page.
-
setAdapter(PagerAdapter adapter)
:設(shè)置提供views的adapter
set a PagerAdapter that will supply views for this pager as needed.
-
addOnPageChangeListener(OnPageChangeListener)
:設(shè)置動作監(jiān)聽器 -
OnPageChangeListener
:-
onPageScrollStateChanged(int state)
:頁面完全停止或空閑時,發(fā)生滑動狀態(tài)時調(diào)用.用于發(fā)現(xiàn)用戶滑動的時刻 -
onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
:當前頁面被滑動時調(diào)用.不管是程序引起的還是用戶觸發(fā)的. -
onPageSelected(int position)
:一個新的頁面被選中時調(diào)用.動畫不一定完成.
-
pageAdapter:
- 實現(xiàn)一個pageAdapter時,必須重載以下方法:
-
instantiateItem(ViewGroup,int)
:在給定位置創(chuàng)建view.可以把view添加此處給出的容器中.
Create the page for the given position. The adapter is responsible for adding the view to the container given here, although it only must ensure this is done by the time it returns from finishUpdate(ViewGroup).
-
destroyItem(ViewGroup, int, Object)
:把page從給定位置移出.
Remove a page for the given position. The adapter is responsible for removing the view from its container, although it only must ensure this is done by the time it returns from finishUpdate(ViewGroup)
-
getCount()
:返回可用的view數(shù)
Return the number of views available.
-
isViewFromObject(view, Object)
:判斷view是否和一個關(guān)鍵object綁定起來
Determines whether a page View is associated with a specific key object as returned by instantiateItem(ViewGroup, int)
- 還有兩個子類可以實現(xiàn):
FragmentPagerAdapter
FragmentStatePagerAdapter
- notifyDataSetChanged():但view改變時,應(yīng)該調(diào)用此函數(shù)!
This method should be called by the application if the data backing this adapter has changed and associated views should update.