android.support.v7.widget.SnapHelper Java Examples
The following examples show how to use
android.support.v7.widget.SnapHelper.
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: MainActivity.java From HorizontalPicker with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); rv = (RecyclerView) findViewById(R.id.rv); PickerLayoutManager pickerLayoutManager = new PickerLayoutManager(this, PickerLayoutManager.HORIZONTAL, false); pickerLayoutManager.setChangeAlpha(true); pickerLayoutManager.setScaleDownBy(0.99f); pickerLayoutManager.setScaleDownDistance(0.8f); adapter = new PickerAdapter(this, getData(100), rv); SnapHelper snapHelper = new LinearSnapHelper(); snapHelper.attachToRecyclerView(rv); rv.setLayoutManager(pickerLayoutManager); rv.setAdapter(adapter); pickerLayoutManager.setOnScrollStopListener(new PickerLayoutManager.onScrollStopListener() { @Override public void selectedView(View view) { Toast.makeText(MainActivity.this, ("Selected value : "+((TextView) view).getText().toString()), Toast.LENGTH_SHORT).show(); } }); }
Example #2
Source File: PostDetailsActivity.java From Capstone-Project with MIT License | 6 votes |
private void setMediaRecyclerViewProperties() { // Set up the recycler view properties. // Create a horizontal layout manager for recycler view. RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false); recyclerViewMedia.setLayoutManager(layoutManager); // Add appropriate decorations to the recycler view items. recyclerViewMedia.addItemDecoration(new MediaItemDecorator(getApplicationContext(), 16)); // Create adapter that will power this recycler view. mMediaRecyclerAdapter = new MediaRecyclerAdapter(null, this); recyclerViewMedia.setAdapter(mMediaRecyclerAdapter); // Add snaphelper that will snap the recycler view items at start. SnapHelper snapHelper = new StartSnapHelper(); snapHelper.attachToRecyclerView(recyclerViewMedia); }
Example #3
Source File: SuntimesActivity.java From SuntimesWidget with GNU General Public License v3.0 | 6 votes |
/** * initialize the card flipper and associated views * @param context a context used to access resources */ private void initCardViews(Context context) { card_adapter = new CardAdapter(context); card_adapter.setCardAdapterListener(cardAdapterListener); card_view = (RecyclerView) findViewById(R.id.info_time_flipper1); card_view.setHasFixedSize(true); card_view.setItemViewCacheSize(7); card_view.setLayoutManager(card_layout = new CardLayoutManager(this)); card_view.addItemDecoration(new CardAdapter.CardViewDecorator(this)); card_view.setAdapter(card_adapter); card_view.scrollToPosition(CardAdapter.TODAY_POSITION); SnapHelper snapHelper = new PagerSnapHelper(); snapHelper.attachToRecyclerView(card_view); card_scroller = new CardAdapter.CardViewScroller(context); card_view.setOnScrollListener(onCardScrollListener); }
Example #4
Source File: FragmentPageSnapAdapter.java From RecyclerPager with Apache License 2.0 | 5 votes |
@Override public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); RecyclerView.OnFlingListener flingListener = recyclerView.getOnFlingListener(); if (flingListener instanceof SnapHelper) { mSnapHelper = (SnapHelper) flingListener; } recyclerView.addOnScrollListener(mScrollListener); }
Example #5
Source File: MainActivity.java From Dagger2-Sample with MIT License | 5 votes |
private void initialiseView() { binding = DataBindingUtil.setContentView(this, R.layout.activity_main); moviesListAdapter = new MoviesListAdapter(this); binding.moviesList.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false)); binding.moviesList.setAdapter(moviesListAdapter); /* SnapHelper to change the background of the activity based on the list item * currently visible */ SnapHelper startSnapHelper = new PagerSnapHelper(position -> { MovieEntity movie = moviesListAdapter.getItem(position); binding.overlayLayout.updateCurrentBackground(movie.getPosterPath()); }); startSnapHelper.attachToRecyclerView(binding.moviesList); }
Example #6
Source File: CharacterActivity.java From Villains-and-Heroes with Apache License 2.0 | 5 votes |
private void setupSectionView(RecyclerView recyclerView, @SectionVO.Type int type) { recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)); recyclerView.setNestedScrollingEnabled(false); recyclerView.setHasFixedSize(true); SectionAdapter adapter = new SectionAdapter(this, type, this); recyclerView.setAdapter(adapter); SnapHelper snapHelper = new LinearSnapHelper(); snapHelper.attachToRecyclerView(recyclerView); }
Example #7
Source File: EquinoxView.java From SuntimesWidget with GNU General Public License v3.0 | 5 votes |
private void init(Context context, AttributeSet attrs) { initLocale(context); themeViews(context); LayoutInflater.from(context).inflate(R.layout.layout_view_equinox, this, true); if (attrs != null) { LinearLayout.LayoutParams lp = generateLayoutParams(attrs); options.centered = ((lp.gravity == Gravity.CENTER) || (lp.gravity == Gravity.CENTER_HORIZONTAL)); } empty = (TextView)findViewById(R.id.txt_empty); card_view = (RecyclerView)findViewById(R.id.info_equinoxsolstice_flipper1); card_view.setHasFixedSize(true); card_view.setItemViewCacheSize(7); card_view.setLayoutManager(card_layout = new CardLayoutManager(context)); //card_view.addItemDecoration(new CardAdapter.CardViewDecorator(context)); card_adapter = new EquinoxViewAdapter(context, options); card_adapter.setEquinoxViewListener(cardListener); card_view.setAdapter(card_adapter); card_view.scrollToPosition(EquinoxViewAdapter.CENTER_POSITION); SnapHelper snapHelper = new PagerSnapHelper(); snapHelper.attachToRecyclerView(card_view); card_scroller = new CardAdapter.CardViewScroller(context); boolean minimized = isMinimized(); if (!minimized) { card_view.setOnScrollListener(onCardScrollListener); } card_view.setLayoutFrozen(minimized); if (isInEditMode()) { updateViews(context); } }
Example #8
Source File: RecyclerViewPageChangeListenerHelper.java From Focus with GNU General Public License v3.0 | 4 votes |
public RecyclerViewPageChangeListenerHelper(SnapHelper snapHelper, OnPageChangeListener onPageChangeListener) { this.snapHelper = snapHelper; this.onPageChangeListener = onPageChangeListener; }
Example #9
Source File: RecyclerViewPageChangeListenerHelper.java From Focus with GNU General Public License v3.0 | 4 votes |
public RecyclerViewPageChangeListenerHelper(SnapHelper snapHelper, OnPageChangeListener onPageChangeListener) { this.snapHelper = snapHelper; this.onPageChangeListener = onPageChangeListener; }
Example #10
Source File: SimpleRecyclerView.java From SimpleRecyclerView with Apache License 2.0 | 4 votes |
public void enableSnappy(@NonNull SnapAlignment alignment) { SnapHelper snapHelper = alignment.equals(SnapAlignment.CENTER) ? new LinearSnapHelper() : new StartSnapHelper(spacing); snapHelper.attachToRecyclerView(this); }