當前位置: 首頁>>代碼示例>>Java>>正文


Java LinearLayoutManager.setInitialPrefetchItemCount方法代碼示例

本文整理匯總了Java中android.support.v7.widget.LinearLayoutManager.setInitialPrefetchItemCount方法的典型用法代碼示例。如果您正苦於以下問題:Java LinearLayoutManager.setInitialPrefetchItemCount方法的具體用法?Java LinearLayoutManager.setInitialPrefetchItemCount怎麽用?Java LinearLayoutManager.setInitialPrefetchItemCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v7.widget.LinearLayoutManager的用法示例。


在下文中一共展示了LinearLayoutManager.setInitialPrefetchItemCount方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: bind

import android.support.v7.widget.LinearLayoutManager; //導入方法依賴的package包/類
@Override
public void bind(EpubView epubView, ViewGroup parent) {
    this.epubView = epubView;
    LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    binding = EpubVerticalVerticalContentBinding.inflate(inflater, parent, true);

    LinearLayoutManager layoutManager = new LinearLayoutManager(epubView.getContext());
    layoutManager.setInitialPrefetchItemCount(2);
    binding.recyclerview.setLayoutManager(layoutManager);
    chapterAdapter = new ChapterAdapter(this, epubView);
    binding.recyclerview.setAdapter(chapterAdapter);
    binding.recyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
            View firstVisibleView = layoutManager.findViewByPosition(firstVisibleItemPosition);
            scrollPosition.onNext(new Pair<>(firstVisibleItemPosition, firstVisibleView.getTop()));
            setCurrentChapter(firstVisibleItemPosition);
        }
    });

    scrollPosition
            .sample(200, TimeUnit.MILLISECONDS)
            .observeOn(AndroidSchedulers.mainThread())
            .doOnNext(positionTopPair -> {
                ChapterAdapter.ChapterViewHolder holder = (ChapterAdapter.ChapterViewHolder) binding.recyclerview.findViewHolderForAdapterPosition(positionTopPair.first);
                if (holder != null) {
                    float density = epubView.getContext().getResources().getDisplayMetrics().density;
                    holder.binding.webview.callJavascriptMethod("updateFirstVisibleElementByTopPosition", -positionTopPair.second/density);
                }
            })
            .subscribe(new BaseDisposableObserver<>());
}
 
開發者ID:smartmobilefactory,項目名稱:EpubReaderAndroid,代碼行數:35,代碼來源:VerticalWithVerticalContentEpubDisplayStrategy.java


注:本文中的android.support.v7.widget.LinearLayoutManager.setInitialPrefetchItemCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。