Java Code Examples for android.support.v7.widget.RecyclerView#addOnScrollListener()
The following examples show how to use
android.support.v7.widget.RecyclerView#addOnScrollListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectableListLayout.java From 365browser with Apache License 2.0 | 6 votes |
/** * Initializes the RecyclerView. * * @param adapter The adapter that provides a binding from an app-specific data set to views * that are displayed within the RecyclerView. * @return The RecyclerView itself. */ public RecyclerView initializeRecyclerView(Adapter<RecyclerView.ViewHolder> adapter) { mAdapter = adapter; mAdapter.registerAdapterDataObserver(mAdapterObserver); mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view); mRecyclerView.setAdapter(mAdapter); mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); mRecyclerView.setHasFixedSize(true); mRecyclerView.addOnScrollListener(new OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { setToolbarShadowVisibility(); } }); mItemAnimator = mRecyclerView.getItemAnimator(); return mRecyclerView; }
Example 2
Source File: BoxingBottomSheetFragment.java From boxing with Apache License 2.0 | 6 votes |
@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); mRecycleView.setHasFixedSize(true); mLoadingView = (ProgressBar) view.findViewById(R.id.loading); GridLayoutManager gridLayoutManager = new HackyGridLayoutManager(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); }
Example 3
Source File: GravitySnapHelper.java From SuntimesWidget with GNU General Public License v3.0 | 6 votes |
@Override public void attachToRecyclerView(@Nullable RecyclerView recyclerView) throws IllegalStateException { if (this.recyclerView != null) { this.recyclerView.removeOnScrollListener(scrollListener); } if (recyclerView != null) { recyclerView.setOnFlingListener(null); if (gravity == Gravity.START || gravity == Gravity.END) { isRtl = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL; } recyclerView.addOnScrollListener(scrollListener); this.recyclerView = recyclerView; } else { this.recyclerView = null; } super.attachToRecyclerView(recyclerView); }
Example 4
Source File: RecyclerViewFragment.java From KA27 with Apache License 2.0 | 6 votes |
public void setOnScrollListener(RecyclerView recyclerView) { if (recyclerView != null) { int paddingBottom = recyclerView.getPaddingBottom() + getResources().getDimensionPixelSize(R.dimen.basecard_padding); if (applyOnBootLayout != null) { recyclerView.setPadding(0, applyOnBootLayout.getHeight(), 0, firstOpening ? paddingBottom : recyclerView.getPaddingBottom()); resetTranslations(); if (!Utils.isTV(getActivity())) recyclerView.addOnScrollListener(onScrollListener = new CustomScrollListener()); } else recyclerView.setPadding(0, 0, 0, firstOpening ? paddingBottom : recyclerView.getPaddingBottom()); recyclerView.setClipToPadding(false); } }
Example 5
Source File: RecyclerViewFastScroller.java From Silence with GNU General Public License v3.0 | 6 votes |
public void setRecyclerView(final @NonNull RecyclerView recyclerView) { if (this.recyclerView != null) { this.recyclerView.removeOnScrollListener(onScrollListener); } this.recyclerView = recyclerView; recyclerView.addOnScrollListener(onScrollListener); recyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { recyclerView.getViewTreeObserver().removeOnPreDrawListener(this); if (handle.isSelected()) return true; final int verticalScrollOffset = recyclerView.computeVerticalScrollOffset(); final int verticalScrollRange = recyclerView.computeVerticalScrollRange(); float proportion = (float)verticalScrollOffset / ((float)verticalScrollRange - height); setBubbleAndHandlePosition(height * proportion); return true; } }); }
Example 6
Source File: MainActivity.java From FocusResize with Apache License 2.0 | 5 votes |
private void createCustomAdapter(RecyclerView recyclerView, LinearLayoutManager linearLayoutManager) { CustomAdapter customAdapter = new CustomAdapter(this, (int) getResources().getDimension(R.dimen.custom_item_height)); customAdapter.addItems(addItems()); if (recyclerView != null) { recyclerView.setLayoutManager(linearLayoutManager); recyclerView.setHasFixedSize(true); recyclerView.setAdapter(customAdapter); recyclerView.addOnScrollListener(new FocusResizeScrollListener<>(customAdapter, linearLayoutManager)); } }
Example 7
Source File: StaggeredLayoutManagerUtils.java From RecyclerViewTools with Apache License 2.0 | 5 votes |
/** * Fix for some odd behavior with StaggeredGridLayoutManager animations * * @param recyclerView * @param aroundPosition */ public static void onItemChanged(RecyclerView recyclerView, int aroundPosition) { if (recyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) { recyclerView.addOnScrollListener(new ScrollHack(aroundPosition)); } else { throw new IllegalArgumentException("This method is to fix issues on StaggeredGridLayoutManager"); } }
Example 8
Source File: BindSuperAdapter.java From LazyRecyclerAdapter with MIT License | 5 votes |
@Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); RecyclerView.Adapter adapter = recyclerView.getAdapter(); mRecyclerView = recyclerView; if (adapter instanceof BindSuperAdapter) { mWrapAdapter = new WrapAdapter((BindSuperAdapter) adapter); recyclerView.setAdapter(mWrapAdapter); recyclerView.setOnTouchListener(this); recyclerView.addOnScrollListener(mScrollListener); adapter.registerAdapterDataObserver(mDataObserver); mDataObserver.onChanged(); } }
Example 9
Source File: RefreshView.java From PullRefreshLoadRecyclerView with MIT License | 5 votes |
public void bindWith(final RecyclerView recyclerView) { this.recyclerView = recyclerView; recyclerView.removeOnScrollListener(computePositionListener); recyclerView.addOnScrollListener(computePositionListener); recyclerView.getViewTreeObserver().addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { recyclerView.getViewTreeObserver().removeGlobalOnLayoutListener(this); setTranslationY(-getMeasuredHeight()); } }); }
Example 10
Source File: FastScroller.java From Muzesto with GNU General Public License v3.0 | 4 votes |
public void setRecyclerView(RecyclerView recyclerView) { this.recyclerView = recyclerView; recyclerView.addOnScrollListener(scrollListener); }
Example 11
Source File: LibraryFragment.java From homeassist with Apache License 2.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_library, container, false); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view); ArrayList<Library> libraries = new ArrayList<>(); libraries.add(new Library("Retrofit", "Square", "Apache v2.0", "https://square.github.io")); libraries.add(new Library("OkHttp", "Square", "Apache v2.0", "https://square.github.io")); libraries.add(new Library("Material Dialog", "Aidan Follestad", "Apache v2.0", "https://github.com/afollestad")); libraries.add(new Library("Glide", "Bump Technologies", "Apache v2.0", "https://github.com/bumptech")); libraries.add(new Library("Gson", "Google", "Apache v2.0", "https://github.com/google/gson")); libraries.add(new Library("Android Support Library", "Google", "Apache v2.0", "https://developer.android.com/topic/libraries/support-library/")); libraries.add(new Library("RecyclerView-FlexibleDivider", "Yoshihito Ikeda", "Apache v2.0", "https://github.com/yqritc")); libraries.add(new Library("DiscreteSeekBar", "Gustavo Claramunt", "Apache v2.0", "https://github.com/AnderWeb")); libraries.add(new Library("MaterialEditText", "Kai Zhu (rengwuxian)", "Apache v2.0", "https://github.com/rengwuxian")); libraries.add(new Library("MaterialProgressBar", "Zhang Hai", "Apache v2.0", "https://github.com/DreaminginCodeZH")); libraries.add(new Library("TapTargetView", "Keepsafe Software Inc", "Apache v2.0", "https://github.com/KeepSafe/")); libraries.add(new Library("Konfetti", "Dion Segijn", "ISC License", "https://github.com/DanielMartinus/")); libraries.add(new Library("BlurDialogFragment", "tvbarthel", "Apache 2.0", "https://github.com/tvbarthel/")); libraries.add(new Library("Color Picker", "QuadFlask", "Apache 2.0", "https://github.com/QuadFlask/")); libraries.add(new Library("HelloCharts", "Leszek Wach", "Apache 2.0", "https://github.com/lecho/")); libraries.add(new Library("MaterialSearchView", "Miguel Catalan Bañuls", "Apache 2.0", "https://github.com/MiguelCatalan/")); libraries.add(new Library("Material Design Icons", "Templarian", "WTFPL", "https://github.com/templarian/")); libraries.add(new Library("RxAndroid", "The RxAndroid authors", "Apache 2.0", "https://github.com/ReactiveX/")); libraries.add(new Library("RxJava", "RxJava Contributors", "Apache 2.0", "https://github.com/ReactiveX/")); libraries.add(new Library("StatusBarUtil", "Jaeger Chen", "Apache 2.0", "https://github.com/laobie/")); libraries.add(new Library("MarkdownView", "tiagohm", "Apache 2.0", "https://github.com/tiagohm/")); libraries.add(new Library("CircleImageView", "Henning Dodenhof", "Apache 2.0", "https://github.com/hdodenhof/")); libraries.add(new Library("Material DateTime Picker", "Wouter Dullaert", "Apache 2.0", "https://github.com/wdullaer/")); //libraries.add(new Library("Android Debug Database", "Amit Shekhar", "Apache v2.0", "https://github.com/amitshekhariitbhu/")); //libraries.add(new Library("Calligraphy", "Christopher Jenkins", "Apache v2.0", "https://github.com/chrisjenx")); //libraries.add(new Library("Home Assistant Assets", "Jeremy Geltman", "Creative Commons by-nc-sa v4.0", "https://home-assistant.io/blog/2015/03/08/new-logo/")); //libraries.add(new Library("PhotoView", "Chris Banes", "Apache v2.0", "https://github.com/chrisbanes/PhotoView")); //libraries.add(new Library("Product Tour", "Donghua Xun", "Apache v2.0", "https://github.com/matrixxun/ProductTour")); //libraries.add(new Library("Showcase View", "Alex Curran", "Apache v2.0", "https://github.com/amlcurran/ShowcaseView")); Collections.sort(libraries, new Comparator<Library>() { @Override public int compare(Library lhs, Library rhs) { return lhs.name.compareTo(rhs.name); //descending order } }); mAdapter = new LibraryAdapter(libraries); mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); mRecyclerView.setAdapter(mAdapter); Paint paint = new Paint(); paint.setStrokeWidth(1); paint.setColor(ResourcesCompat.getColor(getResources(), R.color.divider, null)); paint.setAntiAlias(true); paint.setPathEffect(new DashPathEffect(new float[]{25.0f, 25.0f}, 0)); mRecyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(getActivity()).showLastDivider().paint(paint).build()); //.marginResId(R.dimen.leftmargin, R.dimen.rightmargin) mRecyclerView.addOnScrollListener(new SnapScrollListener()); mRecyclerView.setNestedScrollingEnabled(false); return rootView; }
Example 12
Source File: AbstractPagerLLM.java From MultiView with Apache License 2.0 | 4 votes |
@Override public void onAttachedToWindow(RecyclerView view) { super.onAttachedToWindow(view); view.addOnScrollListener(onScrollListener); }
Example 13
Source File: ParentFragment.java From kernel_adiutor with Apache License 2.0 | 4 votes |
@Override public void setOnScrollListener(RecyclerView recyclerView) { recyclerView.addOnScrollListener(onScrollListener == null ? onScrollListener = new CustomOnScrollListener() : onScrollListener); }
Example 14
Source File: netMusicActivity.java From music_player with Open Software License 3.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle info = getIntent().getBundleExtra("info"); if (info != null) { input = info.getString("input"); filter = info.getString("filter"); type = info.getString("type"); } setContentView(R.layout.activity_net_music); Toolbar toolbar = (Toolbar) findViewById(R.id.net_toolbar); toolbar.setTitle("搜索结果"); setSupportActionBar(toolbar); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); //动态注册广播 // dismissReceiver = new DismissReceiver(); // IntentFilter intentFilter = new IntentFilter(); // intentFilter.addAction("dismiss_dialog"); // registerReceiver(dismissReceiver, intentFilter); TextView title = (TextView) findViewById(R.id.net_title); title.setText("以下音乐版权属于原资源提供方"); net = (RecyclerView) findViewById(R.id.netRecyclerView); final LinearLayoutManager layoutManager = new LinearLayoutManager(this); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); net.setLayoutManager(layoutManager); net.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { final int visibleItemCount = recyclerView.getChildCount(); final int totalItemCount = layoutManager.getItemCount(); final int firstVisibleItem = layoutManager.findFirstVisibleItemPosition(); if ((totalItemCount - visibleItemCount) <= (firstVisibleItem + 0) && Stillhasdata && notloading) { new httpTask().execute(); } super.onScrolled(recyclerView, dx, dy); } }); adapter = new netListAdapter(); net.setAdapter(adapter); EventBus.getDefault().register(this); }
Example 15
Source File: ExcelPanel.java From excelPanel with Apache License 2.0 | 4 votes |
protected RecyclerView createMajorContent() { RecyclerView recyclerView = new ExcelMajorRecyclerView(getContext()); recyclerView.setLayoutManager(getLayoutManager()); recyclerView.addOnScrollListener(contentScrollListener); return recyclerView; }
Example 16
Source File: RecyclerViewHandler.java From CommonPullToRefresh with Apache License 2.0 | 4 votes |
@Override public void setOnScrollBottomListener(View contentView, OnScrollBottomListener onScrollBottomListener) { final RecyclerView recyclerView = (RecyclerView) contentView; recyclerView.addOnScrollListener(new RecyclerViewOnScrollListener(onScrollBottomListener)); }
Example 17
Source File: Gallery.java From Slide with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate(Bundle savedInstance) { overrideSwipeFromAnywhere(); subreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT); String multireddit = getIntent().getExtras().getString(EXTRA_MULTIREDDIT); String profile = getIntent().getExtras().getString(EXTRA_PROFILE, ""); if (multireddit != null) { subredditPosts = new MultiredditPosts(multireddit, profile); } else { subredditPosts = new SubredditPosts(subreddit, Gallery.this); } subreddit = multireddit == null ? subreddit : ("multi" + multireddit); if (multireddit == null) { setShareUrl("https://reddit.com/r/" + subreddit); } applyDarkColorTheme(subreddit); super.onCreate(savedInstance); setContentView(R.layout.gallery); getWindow().getDecorView() .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE); long offline = getIntent().getLongExtra("offline", 0L); final OfflineSubreddit submissions = OfflineSubreddit.getSubreddit(subreddit, offline, !Authentication.didOnline, this); baseSubs = new ArrayList<>(); for (Submission s : submissions.submissions) { if (s.getThumbnails() != null && s.getThumbnails().getSource() != null) { baseSubs.add(s); } else if (ContentType.getContentType(s) == ContentType.Type.IMAGE) { baseSubs.add(s); } subredditPosts.getPosts().add(s); } rv = (RecyclerView) findViewById(R.id.content_view); recyclerAdapter = new GalleryView(this, baseSubs, subreddit); RecyclerView.LayoutManager layoutManager = createLayoutManager(getNumColumns(getResources().getConfiguration().orientation)); rv.setLayoutManager(layoutManager); rv.setAdapter(recyclerAdapter); rv.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); int[] firstVisibleItems; firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions( null); if (firstVisibleItems != null && firstVisibleItems.length > 0) { for (int firstVisibleItem : firstVisibleItems) { pastVisiblesItems = firstVisibleItem; } } if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount) { if (subredditPosts instanceof SubredditPosts) { if (!((SubredditPosts) subredditPosts).loading) { ((SubredditPosts) subredditPosts).loading = true; ((SubredditPosts) subredditPosts).loadMore(Gallery.this, Gallery.this, false, subreddit); } } else if (subredditPosts instanceof MultiredditPosts) { if (!((MultiredditPosts) subredditPosts).loading) { ((MultiredditPosts) subredditPosts).loading = true; (subredditPosts).loadMore(Gallery.this, Gallery.this, false); } } } } }); }
Example 18
Source File: PlaylistFragment.java From Rey-MusicPlayer with Apache License 2.0 | 4 votes |
@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment_album_layout, container, false); mContext = getContext(); setHasOptionsMenu(true); mApp = (Common) mContext.getApplicationContext(); mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView); mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext)); mFastScroller = (FastScroller) view.findViewById(R.id.fast_scroller); TextView emptyText = (TextView) view.findViewById(R.id.empty_text_view); mCreatePlaylistButton = (Button) view.findViewById(R.id.create_playlist); mEmptyStateLayout = (RelativeLayout) view.findViewById(R.id.empty_state); mCreatePlaylistButton.setTypeface(TypefaceHelper.getTypeface(mContext, TypefaceHelper.FUTURA_BOLD)); emptyText.setTypeface(TypefaceHelper.getTypeface(mContext, TypefaceHelper.FUTURA_BOLD)); mCreatePlaylistButton.setOnClickListener(v -> { PlaylistDialog playlistDialog = new PlaylistDialog(); playlistDialog.show(getActivity().getSupportFragmentManager(), "FRAGMENT_TAG"); }); mFastScroller.setRecyclerView(mRecyclerView); mAdapter = new PlaylistAdapter(this); mRecyclerView.setAdapter(mAdapter); mRecyclerView.addOnScrollListener(new HidingScrollListener() { @Override public void onHide() { mOnScrolledListener.onScrolledUp(); } @Override public void onShow() { mOnScrolledListener.onScrolledDown(); } }); return view; }
Example 19
Source File: FastScroller.java From YTPlayer with GNU General Public License v3.0 | 4 votes |
public void setRecyclerView(RecyclerView recyclerView) { this.recyclerView = recyclerView; recyclerView.addOnScrollListener(scrollListener); }
Example 20
Source File: ScrollLayout.java From ScrollLayout with Apache License 2.0 | 2 votes |
/** * Set associated list view, then this layout will only be able to drag down when the list * view is scrolled to top. * * @param recyclerView */ public void setAssociatedRecyclerView(RecyclerView recyclerView) { recyclerView.addOnScrollListener(associatedRecyclerViewListener); updateRecyclerViewScrollState(recyclerView); }