Search in sources :

Example 6 with LinearSmoothScroller

use of android.support.v7.widget.LinearSmoothScroller in project qksms by moezbhatti.

the class SmoothLinearLayoutManager method smoothScrollToPosition.

@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {
    super.smoothScrollToPosition(recyclerView, state, position);
    LinearSmoothScroller smoothScroller = new LinearSmoothScroller(mContext) {

        // This controls the direction in which smoothScroll looks for your view
        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return new PointF(0, 1);
        }

        // This returns the milliseconds it takes to scroll one pixel.
        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
    };
    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
Also used : PointF(android.graphics.PointF) LinearSmoothScroller(android.support.v7.widget.LinearSmoothScroller) DisplayMetrics(android.util.DisplayMetrics)

Example 7 with LinearSmoothScroller

use of android.support.v7.widget.LinearSmoothScroller in project Horizontal-Calendar by Mulham-Raee.

the class HorizontalLayoutManager method smoothScrollToPosition.

@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
    LinearSmoothScroller smoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {

        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return HorizontalLayoutManager.this.computeScrollVectorForPosition(targetPosition);
        }

        // This is the important method. This code will return the amount of time it takes to scroll 1 pixel.
        // This code will request Y milliseconds for every <code>smoothScrollSpeed</code> DP units.
        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return Y / TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, smoothScrollSpeed, displayMetrics);
        }
    };
    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
Also used : LinearSmoothScroller(android.support.v7.widget.LinearSmoothScroller) DisplayMetrics(android.util.DisplayMetrics)

Example 8 with LinearSmoothScroller

use of android.support.v7.widget.LinearSmoothScroller in project AwesomeRecyclerView by forceLain.

the class AwesomeLayoutManager method smoothScrollToPosition.

@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
    if (position >= getItemCount()) {
        Log.e(TAG, "Cannot scroll to " + position + ", item count is " + getItemCount());
        return;
    }
    LinearSmoothScroller scroller = new LinearSmoothScroller(recyclerView.getContext()) {

        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return AwesomeLayoutManager.this.computeScrollVectorForPosition(targetPosition);
        }

        @Override
        protected int getVerticalSnapPreference() {
            return SNAP_TO_START;
        }
    };
    scroller.setTargetPosition(position);
    startSmoothScroll(scroller);
}
Also used : LinearSmoothScroller(android.support.v7.widget.LinearSmoothScroller)

Example 9 with LinearSmoothScroller

use of android.support.v7.widget.LinearSmoothScroller in project UltimateAndroid by cymcsg.

the class TwoWayLayoutManager method smoothScrollToPosition.

@Override
public void smoothScrollToPosition(RecyclerView recyclerView, State state, int position) {
    final LinearSmoothScroller scroller = new LinearSmoothScroller(recyclerView.getContext()) {

        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            if (getChildCount() == 0) {
                return null;
            }
            final int direction = targetPosition < getFirstVisiblePosition() ? -1 : 1;
            if (mIsVertical) {
                return new PointF(0, direction);
            } else {
                return new PointF(direction, 0);
            }
        }

        @Override
        protected int getVerticalSnapPreference() {
            return LinearSmoothScroller.SNAP_TO_START;
        }

        @Override
        protected int getHorizontalSnapPreference() {
            return LinearSmoothScroller.SNAP_TO_START;
        }
    };
    scroller.setTargetPosition(position);
    startSmoothScroll(scroller);
}
Also used : PointF(android.graphics.PointF) LinearSmoothScroller(android.support.v7.widget.LinearSmoothScroller)

Example 10 with LinearSmoothScroller

use of android.support.v7.widget.LinearSmoothScroller in project twoway-view by lucasr.

the class TwoWayLayoutManager method smoothScrollToPosition.

@Override
public void smoothScrollToPosition(RecyclerView recyclerView, State state, int position) {
    final LinearSmoothScroller scroller = new LinearSmoothScroller(recyclerView.getContext()) {

        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            if (getChildCount() == 0) {
                return null;
            }
            final int direction = targetPosition < getFirstVisiblePosition() ? -1 : 1;
            if (mIsVertical) {
                return new PointF(0, direction);
            } else {
                return new PointF(direction, 0);
            }
        }

        @Override
        protected int getVerticalSnapPreference() {
            return LinearSmoothScroller.SNAP_TO_START;
        }

        @Override
        protected int getHorizontalSnapPreference() {
            return LinearSmoothScroller.SNAP_TO_START;
        }
    };
    scroller.setTargetPosition(position);
    startSmoothScroll(scroller);
}
Also used : PointF(android.graphics.PointF) LinearSmoothScroller(android.support.v7.widget.LinearSmoothScroller)

Aggregations

LinearSmoothScroller (android.support.v7.widget.LinearSmoothScroller)14 PointF (android.graphics.PointF)9 RecyclerView (android.support.v7.widget.RecyclerView)4 View (android.view.View)4 DisplayMetrics (android.util.DisplayMetrics)3 LinearInterpolator (android.view.animation.LinearInterpolator)2 AnchorViewState (com.beloo.widget.chipslayoutmanager.anchor.AnchorViewState)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1