本文整理匯總了Java中android.support.v7.widget.RecyclerView.addOnScrollListener方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.addOnScrollListener方法的具體用法?Java RecyclerView.addOnScrollListener怎麽用?Java RecyclerView.addOnScrollListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.RecyclerView
的用法示例。
在下文中一共展示了RecyclerView.addOnScrollListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreateView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mRecyclerView = new RecyclerView(getContext());
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
mRecyclerView.setAdapter(new SimpleAdapter());
mRecyclerView.setClipToPadding(false);
mRecyclerView.setPadding(0, 0, 0,
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()));
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
// track for determining animation direction.
mLastScrollOffsetY = dy;
}
});
return mRecyclerView;
}
示例2: onCreate
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fake_fab_interactive);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
mRv = (RecyclerView) findViewById(R.id.rv);
mFab = (ImageButton) findViewById(R.id.fab);
mToolbarBottomMargin = ((ViewGroup.MarginLayoutParams) mToolbar.getLayoutParams()).bottomMargin;
mFabBottomMargin = ((ViewGroup.MarginLayoutParams) mFab.getLayoutParams()).bottomMargin;
mRv.setLayoutManager(new LinearLayoutManager(this));
mRv.setAdapter(new MyAdapter(mData));
mRv.addOnScrollListener(new FakeFabScrollListener(this));
}
示例3: onCreateView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_photo_gallery, container, false);
mPhotoRecyclerView = (RecyclerView) v.findViewById(R.id.photo_recycler_view);
mGridLayoutManager = new GridLayoutManager(getActivity(), SPAN);
mPhotoRecyclerView.setLayoutManager(mGridLayoutManager);
mScrollListener = new PhotoGalleryOnScrollListener(mGridLayoutManager) {
@Override
public void onLoadMore(int nPhotos, RecyclerView view) {
requestPhotos(nPhotos);
}
};
// asociate model with recycler view
mPhotoGalleryAdapter = new PhotoGalleryAdapter(mPhotos, mApp);
mPhotoRecyclerView.setAdapter(mPhotoGalleryAdapter);
mPhotoRecyclerView.addOnScrollListener(mScrollListener);
return v;
}
示例4: onViewCreated
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mEmptyTxt = (TextView) view.findViewById(R.id.empty_txt);
mRecycleView = (RecyclerView) view.findViewById(R.id.media_recycleview);
mLoadingView = (ProgressBar) view.findViewById(R.id.loading);
GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), GRID_COUNT);
gridLayoutManager.setSmoothScrollbarEnabled(true);
mRecycleView.setLayoutManager(gridLayoutManager);
mRecycleView.addItemDecoration(new SpacesItemDecoration(getResources().getDimensionPixelOffset(R.dimen.boxing_media_margin), GRID_COUNT));
mRecycleView.setAdapter(mMediaAdapter);
mRecycleView.addOnScrollListener(new ScrollListener());
mMediaAdapter.setOnMediaClickListener(new OnMediaClickListener());
mMediaAdapter.setOnCameraClickListener(new OnCameraClickListener());
view.findViewById(R.id.finish_txt).setOnClickListener(this);
}
示例5: AllInOneInquiryListCustomAdapter
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public AllInOneInquiryListCustomAdapter(Context context, ArrayList<MainRecord> list, RecyclerView recyclerView, OnAdapterSupport listener, RecordListSupporter recordSupporter) {
this.context = context;
this.list = list;
this.onAdapterSupport = listener;
this.recordSupporter = recordSupporter;
if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
recyclerView.addOnScrollListener(new ScrollListener() {
@Override
public void onHide() {
hideViews();
}
@Override
public void onShow() {
showViews();
}
});
}
}
示例6: setRecyclerView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public void setRecyclerView(RecyclerView recyclerView) {
if (mRecyclerView != null) {
mRecyclerView.removeOnScrollListener(mScrollListener);
mRecyclerView.removeOnLayoutChangeListener(mLayoutChangeListener);
}
mRecyclerView = recyclerView;
recyclerView.addOnScrollListener(mScrollListener);
recyclerView.addOnLayoutChangeListener(mLayoutChangeListener);
registerAdapterDataObserver();
}
示例7: onDetachedFromRecyclerView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
super.onDetachedFromRecyclerView(recyclerView);
recyclerView.addOnScrollListener(null);
}
示例8: onCreateView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_photos, container, false);
root.findViewById(R.id.toolbar).setVisibility(View.GONE);
RecyclerView recyclerView = root.findViewById(android.R.id.list);
mEmpty = root.findViewById(R.id.empty);
int columns = getContext().getResources().getInteger(R.integer.photos_column_count);
GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), columns);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.addOnScrollListener(new PicassoPauseOnScrollListener(Constants.PICASSO_TAG));
recyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener() {
@Override
public void onScrollToLastElement() {
getPresenter().fireScrollToEnd();
}
});
mSwipeRefreshLayout = root.findViewById(R.id.refresh);
mSwipeRefreshLayout.setOnRefreshListener(this);
ViewUtils.setupSwipeRefreshLayoutWithCurrentTheme(getActivity(), mSwipeRefreshLayout);
mAdapter = new FavePhotosAdapter(getActivity(), Collections.emptyList());
mAdapter.setPhotoSelectionListener(this);
recyclerView.setAdapter(mAdapter);
resolveEmptyTextVisibility();
return root;
}
示例9: onCreate
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView giphyLogoView = (ImageView) findViewById(R.id.giphy_logo_view);
GlideApp.with(this)
.load(R.raw.large_giphy_logo)
.into(giphyLogoView);
RecyclerView gifList = (RecyclerView) findViewById(R.id.gif_list);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
gifList.setLayoutManager(layoutManager);
RequestBuilder<Drawable> gifItemRequest = GlideApp.with(this)
.asDrawable();
ViewPreloadSizeProvider<Api.GifResult> preloadSizeProvider =
new ViewPreloadSizeProvider<>();
adapter = new GifAdapter(this, gifItemRequest, preloadSizeProvider);
gifList.setAdapter(adapter);
RecyclerViewPreloader<Api.GifResult> preloader =
new RecyclerViewPreloader<>(GlideApp.with(this), adapter, preloadSizeProvider, 4);
gifList.addOnScrollListener(preloader);
gifList.setRecyclerListener(new RecyclerListener() {
@Override
public void onViewRecycled(ViewHolder holder) {
// This is an optimization to reduce the memory usage of RecyclerView's recycled view pool
// and good practice when using Glide with RecyclerView.
GifViewHolder gifViewHolder = (GifViewHolder) holder;
GlideApp.with(MainActivity.this).clear(gifViewHolder.gifView);
}
});
}
示例10: setRecyclerView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public void setRecyclerView(@NonNull RecyclerView recyclerView) {
if (this.recyclerView != recyclerView) {
if (this.recyclerView != null)
this.recyclerView.removeOnScrollListener(onScrollListener);
this.recyclerView = recyclerView;
recyclerView.addOnScrollListener(onScrollListener);
}
}
示例11: setRecyclerViewScrollListener
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void setRecyclerViewScrollListener() {
layoutManagerType = null;
final RecyclerView recyclerView = (RecyclerView) child;
if (recyclerView.getAdapter() == null) {
return;
}
if (!(recyclerView.getAdapter() instanceof BaseRecyclerAdapter)) {
// throw new RuntimeException("Recylerview的adapter請繼承 BaseRecyclerAdapter");
LogUtils.w(RECYCLERVIEW_ADAPTER_WARIN);
return;
}
final BaseRecyclerAdapter adapter = (BaseRecyclerAdapter) recyclerView.getAdapter();
adapter.insideEnableFooter(mParent.getPullLoadEnable());
recyclerView.removeOnScrollListener(mOnScrollListener);
mOnScrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (mRecyclerViewScrollListener != null) {
mRecyclerViewScrollListener.onScrollStateChanged(recyclerView, newState);
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
onRecyclerViewScrolled(recyclerView, adapter, dx, dy, false);
}
};
recyclerView.addOnScrollListener(mOnScrollListener);
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager != null && layoutManager instanceof GridLayoutManager) {
GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
gridLayoutManager.setSpanSizeLookup(new XSpanSizeLookup(adapter, gridLayoutManager.getSpanCount()));
}
initFooterCallBack(adapter, mParent);
}
示例12: attachToRecyclerView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void attachToRecyclerView(@Nullable RecyclerView recyclerView) throws IllegalStateException {
super.attachToRecyclerView(recyclerView);
if (recyclerView != null) {
recyclerView.removeOnScrollListener(mScrollListener);
recyclerView.addOnScrollListener(mScrollListener);
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof LinearLayoutManager) {
mOrientation = ((LinearLayoutManager) layoutManager).getOrientation();
}
}
}
示例13: initRecyclerView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* Implement this method to customize the AbsListView
*/
protected void initRecyclerView(View view) {
mRecycler = (RecyclerView) view.findViewById(android.R.id.list);
tipView = (TextView) view.findViewById(R.id.tvTip);
setItemAnimator(null);
if (mRecycler != null) {
mRecycler.setHasFixedSize(true);
mRecycler.setClipToPadding(mClipToPadding);
mInternalOnScrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (mExternalOnScrollListener != null)
mExternalOnScrollListener.onScrolled(recyclerView, dx, dy);
}
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (mExternalOnScrollListener != null)
mExternalOnScrollListener.onScrollStateChanged(recyclerView, newState);
}
};
mRecycler.addOnScrollListener(mInternalOnScrollListener);
if (mPadding != -1.0f) {
mRecycler.setPadding(mPadding, mPadding, mPadding, mPadding);
} else {
mRecycler.setPadding(mPaddingLeft, mPaddingTop, mPaddingRight, mPaddingBottom);
}
if (mScrollbarStyle != -1) {
mRecycler.setScrollBarStyle(mScrollbarStyle);
}
switch (mScrollbar) {
case 0:
setVerticalScrollBarEnabled(false);
break;
case 1:
setHorizontalScrollBarEnabled(false);
break;
case 2:
setVerticalScrollBarEnabled(false);
setHorizontalScrollBarEnabled(false);
break;
}
}
}
示例14: onCreateView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle args = getArguments();
photoSize = args.getInt(IMAGE_SIZE_KEY);
thumbnail = args.getBoolean(THUMBNAIL_KEY);
fullRequest = GlideApp.with(this)
.asDrawable()
.centerCrop()
.transition(withNoTransition());
thumbnailRequest = GlideApp.with(this)
.asDrawable()
.diskCacheStrategy(DiskCacheStrategy.DATA)
.centerCrop()
.override(Api.SQUARE_THUMB_SIZE)
.transition(withNoTransition());
preloadRequest =
thumbnail ? thumbnailRequest.clone().priority(Priority.HIGH) : fullRequest;
final View result = inflater.inflate(R.layout.flickr_photo_grid, container, false);
final int gridMargin = getResources().getDimensionPixelOffset(R.dimen.grid_margin);
int spanCount = getResources().getDisplayMetrics().widthPixels / (photoSize + (2 * gridMargin));
grid = (RecyclerView) result.findViewById(R.id.flickr_photo_grid);
layoutManager = new GridLayoutManager(getActivity(), spanCount);
grid.setLayoutManager(layoutManager);
grid.addItemDecoration(new RecyclerView.ItemDecoration() {
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
RecyclerView.State state) {
outRect.set(gridMargin, gridMargin, gridMargin, gridMargin);
}
});
grid.setRecyclerListener(new RecyclerView.RecyclerListener() {
@Override
public void onViewRecycled(RecyclerView.ViewHolder holder) {
PhotoViewHolder photoViewHolder = (PhotoViewHolder) holder;
GlideApp.with(FlickrPhotoGrid.this).clear(photoViewHolder.imageView);
}
});
int heightCount = getResources().getDisplayMetrics().heightPixels / photoSize;
grid.getRecycledViewPool().setMaxRecycledViews(0, spanCount * heightCount * 2);
grid.setItemViewCacheSize(0);
adapter = new PhotoAdapter();
grid.setAdapter(adapter);
FixedPreloadSizeProvider<Photo> preloadSizeProvider =
new FixedPreloadSizeProvider<>(photoSize, photoSize);
RecyclerViewPreloader<Photo> preloader = new RecyclerViewPreloader<>(Glide.with(this), adapter,
preloadSizeProvider, args.getInt(PRELOAD_KEY));
grid.addOnScrollListener(preloader);
if (currentPhotos != null) {
adapter.setPhotos(currentPhotos);
}
if (savedInstanceState != null) {
int index = savedInstanceState.getInt(STATE_POSITION_INDEX);
grid.scrollToPosition(index);
}
return result;
}
示例15: onCreateView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
View root = inflater.inflate(R.layout.fragment_friends, container, false);
RecyclerView mRecyclerView = root.findViewById(R.id.list);
mSwipeRefreshLayout = root.findViewById(R.id.refresh);
mSwipeRefreshLayout.setOnRefreshListener(() -> getPresenter().fireRefresh());
ViewUtils.setupSwipeRefreshLayoutWithCurrentTheme(getActivity(), mSwipeRefreshLayout);
LinearLayoutManager manager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
mRecyclerView.setLayoutManager(manager);
mRecyclerView.addOnScrollListener(new PicassoPauseOnScrollListener(Constants.PICASSO_TAG));
mRecyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener() {
@Override
public void onScrollToLastElement() {
getPresenter().fireScrollToEnd();
}
});
MySearchView mySearchView = root.findViewById(R.id.searchview);
mySearchView.setRightButtonVisibility(false);
mySearchView.setLeftIcon(R.drawable.magnify);
mySearchView.setOnQueryTextListener(new MySearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
getPresenter().fireSearchRequestChanged(query);
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
getPresenter().fireSearchRequestChanged(newText);
return false;
}
});
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mySearchView.getWindowToken(), 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
root.findViewById(R.id.appbar).setElevation(0);
}
mAdapter = new FriendsRecycleAdapter(Collections.emptyList(), getActivity());
mAdapter.setListener(this);
mRecyclerView.setAdapter(mAdapter);
return root;
}