Java Code Examples for android.support.v7.widget.PagerSnapHelper#attachToRecyclerView()
The following examples show how to use
android.support.v7.widget.PagerSnapHelper#attachToRecyclerView() .
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: ViewPagerActivity.java From recyclerviewItemDecorations with MIT License | 6 votes |
@Override public void onCreateRecyclerView(Bundle savedInstanceState) { int backgroundColor = 0xFF665F30; Context context = this; recyclerView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; recyclerView.setBackgroundColor(backgroundColor); SimpleViewAdapter adapter = new SimpleViewAdapter(5, R.layout.item_view_pager_page); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)); // add pager behavior PagerSnapHelper snapHelper = new PagerSnapHelper(); snapHelper.attachToRecyclerView(recyclerView); // pager indicator recyclerView.addItemDecoration(new LinePagerIndicatorDecoration()); }
Example 2
Source File: LoopBanner.java From LoopBanner with Apache License 2.0 | 5 votes |
private void setupViewPager(final RecyclerView viewPager) { mLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false); viewPager.setLayoutManager(mLayoutManager); initFirstWidth(); mSnapHelper = new PagerSnapHelper(); mSnapHelper.attachToRecyclerView(viewPager); viewPager.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); final int cur = findCurPosition(); if (cur != mLastPosition) { Tools.logI(TAG, "onPageSelected: " + cur); mCurrentIndex = cur; notifySelectChange(cur); updateIndicators(cur, mLastPosition); mLastPosition = cur; } switch (newState) { case SCROLL_STATE_DRAGGING: stopInternal(); break; case SCROLL_STATE_IDLE: startInternal(false); break; default: } } }); // if (mLrScale > 0 && mLrScale < 1) { // viewPager.setPageTransformer(false, new ScalePageTransformer(mLrScale)); // } }
Example 3
Source File: PreviewActivity.java From imsdk-android with MIT License | 5 votes |
private void initRecyclerView() { rvPhotos = (RecyclerView) findViewById(R.id.rv_photos); adapter = new PreviewPhotosAdapter(this, photos, this); lm = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); rvPhotos.setLayoutManager(lm); rvPhotos.setAdapter(adapter); rvPhotos.scrollToPosition(index); toggleSelector(); snapHelper = new PagerSnapHelper(); snapHelper.attachToRecyclerView(rvPhotos); rvPhotos.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); View view = snapHelper.findSnapView(lm); if (view == null) { return; } int position = lm.getPosition(view); if (lastPosition == position) { return; } lastPosition = position; previewFragment.setSelectedPosition(-1); tvNumber.setText(getString(R.string.preview_current_number_easy_photos, lastPosition + 1, photos.size())); toggleSelector(); PreviewPhotosAdapter.PreviewPhotosViewHolder holder = (PreviewPhotosAdapter.PreviewPhotosViewHolder) rvPhotos.getChildViewHolder(view); if (holder == null || holder.ivPhoto == null) { return; } if (holder.ivPhoto.getScale() != 1f) { holder.ivPhoto.setScale(1f, true); } } }); tvNumber.setText(getString(R.string.preview_current_number_easy_photos, index + 1, photos.size())); }
Example 4
Source File: HomeActivity.java From Cinema-App-Concept with MIT License | 5 votes |
public void init(){ //Changing the font throughout the activity regular = Typeface.createFromAsset(getAssets(), "fonts/product_san_regular.ttf"); bold = Typeface.createFromAsset(getAssets(),"fonts/product_sans_bold.ttf"); regularFontChanger = new FontChanger(regular); boldFontChanger = new FontChanger(bold); moviesRV = findViewById(R.id.moviesRV); movieList = new ArrayList<>(); movieAdapter = new MovieAdapter(movieList,HomeActivity.this); layoutManager = new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false); snapHelper = new PagerSnapHelper(); snapHelper.attachToRecyclerView(moviesRV); moviesRV.setLayoutManager(layoutManager); moviesRV.addItemDecoration(new LinePagerIndicatorDecoration(HomeActivity.this)); moviesRV.setAdapter(movieAdapter); backdropIV = findViewById(R.id.backdropIV); MiddleItemFinder.MiddleItemCallback callback = new MiddleItemFinder.MiddleItemCallback() { @Override public void scrollFinished(int middleElement) { // interaction with middle item onActiveCardChange(middleElement); } }; moviesRV.addOnScrollListener( new MiddleItemFinder(getApplicationContext(), layoutManager, callback, RecyclerView.SCROLL_STATE_IDLE)); }
Example 5
Source File: ScrollManager.java From Recyclerview-Gallery with Apache License 2.0 | 5 votes |
/** * 初始化SnapHelper * * @param helper int */ public void initSnapHelper(int helper) { switch (helper) { case GalleryRecyclerView.LINEAR_SNAP_HELPER: LinearSnapHelper mLinearSnapHelper = new LinearSnapHelper(); mLinearSnapHelper.attachToRecyclerView(mGalleryRecyclerView); break; case GalleryRecyclerView.PAGER_SNAP_HELPER: PagerSnapHelper mPagerSnapHelper = new PagerSnapHelper(); mPagerSnapHelper.attachToRecyclerView(mGalleryRecyclerView); break; default: break; } }
Example 6
Source File: MovieDetailsActivity.java From Cinema-App-Concept with MIT License | 4 votes |
public void init(){ postponeEnterTransition(); descCV = findViewById(R.id.descCV); //Changing the font throughout the activity regular = Typeface.createFromAsset(getAssets(), "fonts/product_san_regular.ttf"); bold = Typeface.createFromAsset(getAssets(),"fonts/product_sans_bold.ttf"); regularFontChanger = new FontChanger(regular); boldFontChanger = new FontChanger(bold); movieNameTV = findViewById(R.id.movieNameTV); genreTV = findViewById(R.id.genreTV); descTV = findViewById(R.id.descriptionTV); backdropIV = findViewById(R.id.backdropIV); sessionLL = findViewById(R.id.sessionLL); timeSelectionLL = findViewById(R.id.timeSelectionLL); detailsLL = findViewById(R.id.detailsLL); sessionTimeButton = findViewById(R.id.sessionTimeBTN); picturesRV = findViewById(R.id.picturesRV); ptMovieList = new ArrayList<>(); ptAdapter = new PTAdapter(ptMovieList,MovieDetailsActivity.this); bookTicketsBTN = findViewById(R.id.bookTicketsBTN); layoutManager = new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false); snapHelper = new PagerSnapHelper(); snapHelper.attachToRecyclerView(picturesRV); picturesRV.setLayoutManager(layoutManager); picturesRV.addItemDecoration(new LinePagerIndicatorDecoration(MovieDetailsActivity.this)); picturesRV.setAdapter(ptAdapter); picturesRV.post(new Runnable() { @Override public void run() { supportStartPostponedEnterTransition(); } }); MiddleItemFinder.MiddleItemCallback callback = new MiddleItemFinder.MiddleItemCallback() { @Override public void scrollFinished(int middleElement) { // interaction with middle item currentPosition = middleElement; } }; picturesRV.addOnScrollListener( new MiddleItemFinder(getApplicationContext(), layoutManager, callback, RecyclerView.SCROLL_STATE_IDLE)); picturesRV.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); System.out.println("Testing "+dx); } }); movieTimeRV = findViewById(R.id.movieTimeRV); movieTimeList = new ArrayList<>(); timeSelectionAdapter = new TimeSelectionAdapter(movieTimeList,MovieDetailsActivity.this); LinearLayoutManager layoutManager1 = new LinearLayoutManager(MovieDetailsActivity.this,LinearLayoutManager.HORIZONTAL,false); movieTimeRV.setLayoutManager(layoutManager1); movieTimeRV.setAdapter(timeSelectionAdapter); movieTimeList.add(new MovieTime("7:00 am",300,250)); movieTimeList.add(new MovieTime("11:00 am",300,120)); movieTimeList.add(new MovieTime("3:00 pm",300,60)); movieTimeList.add(new MovieTime("6:45 pm",300,50)); movieTimeList.add(new MovieTime("10:00 pm",300,170)); timeSelectionAdapter.notifyDataSetChanged(); }