protected virtual void ExecuteScroll(int targetPosition, ScrollToRequestedEventArgs eventArgs) { if (eventArgs.Position == ScrollToPosition.MakeVisible) { if (eventArgs.ShouldAnimate) { RecyclerView.SmoothScrollToPosition(targetPosition); } else { RecyclerView.ScrollToPosition(targetPosition); } return; } if (eventArgs.ShouldAnimate) { _scroller.SnapPosition = eventArgs.Position; _scroller.TargetPosition = targetPosition; LayoutManager.StartSmoothScroll(_scroller); } else { LayoutManager.ScrollToPositionWithOffset(targetPosition, CalculateScrollOffset(eventArgs.Position)); } }
private void ScrollToCurrentItem() { if (Element.CurrentIndex == -1 || Control.GetAdapter() == null || Element.CurrentIndex >= Control.GetAdapter().ItemCount) { return; } InternalLogger.Info($"ScrollToCurrentItem() => CurrentItem: {Element.CurrentIndex}"); int offset = 0; if (HorizontalLinearLayoutManager != null) { int itemWidth = PlatformHelper.Instance.DpToPixels( Element.ItemWidth + Element.ItemSpacing + Element.CollectionPadding.HorizontalThickness); int width = Control.MeasuredWidth; switch (Element.SnapStyle) { case SnapStyle.Center: offset = (width / 2) - (itemWidth / 2); break; } } LinearLayoutManager?.ScrollToPositionWithOffset(Element.CurrentIndex, offset); }
private void ScrollToCurrentItem() { if (LinearLayoutManager == null || !_isLandscape) { return; } LinearLayoutManager.ScrollToPositionWithOffset(Element.CurrentIndex, 0); }
public static void ScrollTo(object scroll, float yOffset) { // If RecyclerView RecyclerView recyclerView = scroll as RecyclerView; if (recyclerView != null) { //RecyclerView.scrollTo : UnsupportedOperationException //Moved to the RecyclerView.LayoutManager.scrollToPositionWithOffset //Have to be is RecyclerView.LayoutManager to work (so work with RecyclerView.GridLayoutManager) RecyclerView.LayoutManager layoutManager = recyclerView.GetLayoutManager(); LinearLayoutManager linearLayoutManager = layoutManager as LinearLayoutManager; if (linearLayoutManager != null) { linearLayoutManager.ScrollToPositionWithOffset(0, (int)-yOffset); } else { StaggeredGridLayoutManager staggeredGridLayoutManager = layoutManager as StaggeredGridLayoutManager; if (staggeredGridLayoutManager != null) { staggeredGridLayoutManager.ScrollToPositionWithOffset(0, (int)-yOffset); } } return; } // If ScrollView ScrollView scrollView = scroll as ScrollView; if (scrollView != null) { scrollView.ScrollTo(0, (int)yOffset); return; } // If ListView ListView listView = scroll as ListView; if (listView != null) { listView.ScrollTo(0, (int)yOffset); return; } // If WebView WebView webView = scroll as WebView; if (webView != null) { webView.ScrollTo(0, (int)yOffset); } }
/** * <p>Same as {@linkplain #scrollToPosition(int)} but it scrolls to the position not only make * the position visible.</p> * <p>It depends on {@code LayoutManager} how {@linkplain #scrollToPosition(int)} works, * and currently we know that {@linkplain LinearLayoutManager#scrollToPosition(int)} just * make the position visible.</p> * <p>In LinearLayoutManager, scrollToPositionWithOffset() is provided for scrolling to the position. * This method checks which LayoutManager is set, * and handles which method should be called for scrolling.</p> * <p>Other know classes (StaggeredGridLayoutManager and GridLayoutManager) are not tested.</p> * * @param position position to scroll */ public void ScrollVerticallyToPosition(int position) { LayoutManager lm = GetLayoutManager(); LinearLayoutManager manager = lm as LinearLayoutManager; if (manager != null) { manager.ScrollToPositionWithOffset(position, 0); } else { ScrollToPosition(position); } }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = (LinearLayout)inflater.Inflate(Resource.Layout.reading_and_writing_fragment, container, false); mRecyclerView = rootView.FindViewById <RecyclerView>(Resource.Id.recyclerView); mRecyclerView.HasFixedSize = true; mLayoutManager = new LinearLayoutManager(Activity); mRecyclerView.SetLayoutManager(mLayoutManager); mAdapter = new RecyclerViewAdapter(App.db.GetAllImages(), Activity); mRecyclerView.SetAdapter(mAdapter); if (App.CurrentImagePossition != -1) { if (!(mLayoutManager.FindFirstVisibleItemPosition() <= App.CurrentImagePossition && mLayoutManager.FindLastVisibleItemPosition() >= App.CurrentImagePossition)) { Activity.RunOnUiThread(() => { mLayoutManager.ScrollToPositionWithOffset(App.CurrentImagePossition, 20); });; } //StartPostponedEnterTransition(); } else { //StartPostponedEnterTransition(); } mAdapter.ItemClick += delegate { var view = mRecyclerView.FindViewHolderForAdapterPosition(mAdapter.ClickedPosition) as RecyclerViewHolder; var tmp = view.Slika.TransitionName; GuessingImageFragment gif = new GuessingImageFragment(mAdapter.clickedImage.Id); //gif.SharedElementEnterTransition = new AutoTransition(); //gif.EnterTransition = new Fade(); //setExitTransition(new Fade()); Activity.FragmentManager.BeginTransaction() .Replace(App.fragmentContainer.Id, gif, "guessing") .AddSharedElement(view.Slika, mAdapter.clickedImage.Name) .AddToBackStack(null) .Commit(); App.CurrentFragment = gif; }; return(rootView); }
private void ScrollToCurrentItem() { if (Element.CurrentIndex == -1 || Control.GetAdapter() == null || Element.CurrentIndex >= Control.GetAdapter().ItemCount) { return; } int offset = 0; if (HorizontalLinearLayoutManager != null) { var itemWidth = PlatformHelper.DpToPixels(Element.ItemWidth + Element.ItemSpacing); var width = Control.MeasuredWidth; switch (Element.SnapStyle) { case SnapStyle.Center: offset = (width / 2) - (itemWidth / 2); break; } } LinearLayoutManager?.ScrollToPositionWithOffset(Element.CurrentIndex, offset); }
public void Jump(Location location) => _layoutManager.ScrollToPositionWithOffset(location.AbsoluteVerseNumber, location.Verse == 1 ? -_chapterHeadingVerseOffset : 0);
public virtual void ScrollToRowPosition(int rowPosition, int offset) { mRowHeaderLayoutManager.ScrollToPositionWithOffset(rowPosition, offset); mCellLayoutManager.ScrollToPositionWithOffset(rowPosition, offset); }