viewPager-viewAdapter的使用

viewPager:

  1. 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è)置動(dòng)作監(jiān)聽器
  • OnPageChangeListener:
    • onPageScrollStateChanged(int state):頁面完全停止或空閑時(shí),發(fā)生滑動(dòng)狀態(tài)時(shí)調(diào)用.用于發(fā)現(xiàn)用戶滑動(dòng)的時(shí)刻
    • onPageScrolled(int position, float positionOffset, int positionOffsetPixels):當(dāng)前頁面被滑動(dòng)時(shí)調(diào)用.不管是程序引起的還是用戶觸發(fā)的.
    • onPageSelected(int position):一個(gè)新的頁面被選中時(shí)調(diào)用.動(dòng)畫不一定完成.

pageAdapter:

  • 實(shí)現(xiàn)一個(gè)pageAdapter時(shí),必須重載以下方法:
  1. 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).

  1. 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)

  1. getCount():返回可用的view數(shù)

Return the number of views available.

  1. isViewFromObject(view, Object):判斷view是否和一個(gè)關(guān)鍵object綁定起來

Determines whether a page View is associated with a specific key object as returned by instantiateItem(ViewGroup, int)

  • 還有兩個(gè)子類可以實(shí)現(xiàn):
    • FragmentPagerAdapter
    • FragmentStatePagerAdapter
  • notifyDataSetChanged():但view改變時(shí),應(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.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa閱讀 9,051評論 0 6
  • afinalAfinal是一個(gè)android的ioc,orm框架 https://github.com/yangf...
    passiontim閱讀 15,861評論 2 45
  • 在這個(gè)城市里,只要給錢,幾乎所有的活都有人愿意去做。我也是蕓蕓眾生其中一個(gè)求生的人。今天我下凡做了第一件人生中難以...
    娛樂至死至美閱讀 170評論 0 0
  • 燃寶貝de麻麻閱讀 205評論 0 0
  • 帶著愛與勇敢走自己要走的路,愿你永遠(yuǎn)是喜歡的那個(gè)自己
    沈青青閱讀 156評論 0 2

友情鏈接更多精彩內(nèi)容