當前位置: 首頁>>代碼示例>>Java>>正文


Java LinearSmoothScroller類代碼示例

本文整理匯總了Java中android.support.v7.widget.LinearSmoothScroller的典型用法代碼示例。如果您正苦於以下問題:Java LinearSmoothScroller類的具體用法?Java LinearSmoothScroller怎麽用?Java LinearSmoothScroller使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LinearSmoothScroller類屬於android.support.v7.widget包,在下文中一共展示了LinearSmoothScroller類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入依賴的package包/類
@Override
public void smoothScrollToPosition(final RecyclerView recyclerView, RecyclerView.State state, int position) {
   final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
      @Override
      public int calculateDyToMakeVisible(View view, int snapPreference) {
         final RecyclerView.LayoutManager layoutManager = getLayoutManager();
         if (layoutManager == null || !layoutManager.canScrollVertically()) {
            return 0;
         }

         final int adapterPosition = getPosition(view);
         final int topOffset = getPositionSectionHeaderHeight(adapterPosition);
         final int top = layoutManager.getDecoratedTop(view);
         final int bottom = layoutManager.getDecoratedBottom(view);
         final int start = layoutManager.getPaddingTop() + topOffset;
         final int end = layoutManager.getHeight() - layoutManager.getPaddingBottom();
         return calculateDtToFit(top, bottom, start, end, snapPreference);
      }
   };
   linearSmoothScroller.setTargetPosition(position);
   startSmoothScroll(linearSmoothScroller);
}
 
開發者ID:Codewaves,項目名稱:Sticky-Header-Grid,代碼行數:23,代碼來源:StickyHeaderGridLayoutManager.java

示例2: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {
    LinearSmoothScroller smoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }

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

    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
 
開發者ID:devilist,項目名稱:RecyclerWheelPicker,代碼行數:19,代碼來源:WheelPickerLayoutManager.java

示例3: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
    //
    LinearSmoothScroller smoothScroller = new LinearSmoothScroller(mContext){
        @Nullable
        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return ScrollerLinearLayoutManager.this.computeScrollVectorForPosition
                    (targetPosition);
        }

        //1 pixel -> 0.05 ms
        //1000 pixel -> x=50 ms to go over the height of the screen
        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return 0.05f;
            //return x /displayMetrics.densityDpi;
        }
    };
    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
 
開發者ID:cahergil,項目名稱:Farmacias,代碼行數:23,代碼來源:ScrollerLinearLayoutManager.java

示例4: createSnapScroller

import android.support.v7.widget.LinearSmoothScroller; //導入依賴的package包/類
/**
 * 通過自定義 LinearSmoothScroller 來控製速度
 *
 * @param layoutManager 布局故哪裏去
 * @return 自定義 LinearSmoothScroller
 */
protected LinearSmoothScroller createSnapScroller(RecyclerView.LayoutManager layoutManager) {
    if (!(layoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)) {
        return null;
    }
    return new LinearSmoothScroller(mRecyclerView.getContext()) {
        @Override
        protected void onTargetFound(View targetView, RecyclerView.State state, Action action) {
            int[] snapDistances = calculateDistanceToFinalSnap(mRecyclerView.getLayoutManager(),
                                                               targetView);
            final int dx = snapDistances[0];
            final int dy = snapDistances[1];
            Logi("dx = " + dx);
            Logi("dy = " + dy);
            final int time = calculateTimeForDeceleration(Math.max(Math.abs(dx), Math.abs(dy)));
            if (time > 0) {
                action.update(dx, dy, time, mDecelerateInterpolator);
            }
        }

        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
    };
}
 
開發者ID:GcsSloop,項目名稱:pager-layoutmanager,代碼行數:32,代碼來源:PagerGridSnapHelper.java

示例5: createSnapScroller

import android.support.v7.widget.LinearSmoothScroller; //導入依賴的package包/類
/**
 * Creates a scroller to be used in the snapping implementation.
 *
 * @param layoutManager The {@link RecyclerView.LayoutManager} associated with the attached
 *                      {@link RecyclerView}.
 * @return a {@link LinearSmoothScroller} which will handle the scrolling.
 */
@Nullable
protected LinearSmoothScroller createSnapScroller(RecyclerView.LayoutManager layoutManager) {
    if (!(layoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)) {
        return null;
    }
    return new LinearSmoothScroller(mRecyclerView.getContext()) {
        @Override
        protected void onTargetFound(View targetView, RecyclerView.State state, Action action) {
            int[] snapDistances = calculateDistanceToFinalSnap(mRecyclerView.getLayoutManager(),
                    targetView);
            final int dx = snapDistances[0];
            final int dy = snapDistances[1];
            final int time = calculateTimeForDeceleration(Math.max(Math.abs(dx), Math.abs(dy)));
            if (time > 0) {
                action.update(dx, dy, time, mDecelerateInterpolator);
            }
        }

        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
    };
}
 
開發者ID:hanhailong,項目名稱:GridPagerSnapHelper,代碼行數:32,代碼來源:SnapHelper.java

示例6: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int
        position) {

    final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView
            .getContext()) {

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

        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
    };

    linearSmoothScroller.setTargetPosition(position);
    startSmoothScroll(linearSmoothScroller);
}
 
開發者ID:GcsSloop,項目名稱:diycode,代碼行數:23,代碼來源:SpeedyLinearLayoutManager.java

示例7: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
    LinearSmoothScroller linearSmoothScroller =
            new LinearSmoothScroller(recyclerView.getContext()) {

                @Override
                protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
                    if (scrollSpeed != null) {
                        float speed = scrollSpeed.calculateSpeedPerPixel(super.calculateSpeedPerPixel(displayMetrics));
                        scrollSpeed = null;
                        return speed;
                    }
                    return super.calculateSpeedPerPixel(displayMetrics);
                }

                @Nullable
                @Override
                public PointF computeScrollVectorForPosition(int targetPosition) {
                    return super.computeScrollVectorForPosition(targetPosition);
                }
            };
    linearSmoothScroller.setTargetPosition(position);
    startSmoothScroll(linearSmoothScroller);
}
 
開發者ID:AllanWang,項目名稱:Capsule,代碼行數:25,代碼來源:SGridLayoutManager.java

示例8: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
    LinearSmoothScroller linearSmoothScroller =
            new LinearSmoothScroller(recyclerView.getContext()) {

                @Override
                protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
                    if (scrollSpeed != null) {
                        float speed = scrollSpeed.calculateSpeedPerPixel(super.calculateSpeedPerPixel(displayMetrics));
                        scrollSpeed = null;
                        return speed;
                    }
                    return super.calculateSpeedPerPixel(displayMetrics);
                }

                @Nullable
                @Override
                public PointF computeScrollVectorForPosition(int targetPosition) {
                    return SLinearLayoutManager.this.computeScrollVectorForPosition(targetPosition);
                }
            };
    linearSmoothScroller.setTargetPosition(position);
    startSmoothScroll(linearSmoothScroller);
}
 
開發者ID:AllanWang,項目名稱:Capsule,代碼行數:25,代碼來源:SLinearLayoutManager.java

示例9: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {

    LinearSmoothScroller smoothScroller = new LinearSmoothScroller(mContext) {

        //This controls the direction in which smoothScroll looks
        //for your view
        @Override
        public PointF computeScrollVectorForPosition
        (int targetPosition) {
            return CustomLayoutManager.this.computeScrollVectorForPosition(targetPosition);
        }

        //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);
}
 
開發者ID:Old-Geek,項目名稱:Radio2,代碼行數:25,代碼來源:CustomLayoutManager.java

示例10: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {

    final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {

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

        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
    };

    linearSmoothScroller.setTargetPosition(position);
    try {
        startSmoothScroll(linearSmoothScroller);
    } catch (IllegalArgumentException e) {
        // couldn't scroll for some reason, just ignore
    }
}
 
開發者ID:NightscoutFoundation,項目名稱:xDrip,代碼行數:24,代碼來源:ActivityWithRecycler.java

示例11: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView,
                                   RecyclerView.State state,
                                   int position) {
    RecyclerView.SmoothScroller smoothScroller =
            new LinearSmoothScroller(recyclerView.getContext()) {
                @Override
                public PointF computeScrollVectorForPosition(int targetPosition) {
                    return AgendaLinearLayoutManager.this
                            .computeScrollVectorForPosition(targetPosition);
                }

                @Override
                protected int getVerticalSnapPreference() {
                    return SNAP_TO_START; // override base class behavior
                }
            };
    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
 
開發者ID:tortuvshin,項目名稱:yield,代碼行數:21,代碼來源:ToDayView.java

示例12: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {

    LinearSmoothScroller smoothScroller = new LinearSmoothScroller(mContext) {

        //This controls the direction in which smoothScroll looks
        //for your view
        @Override
        public PointF computeScrollVectorForPosition
        (int targetPosition) {
            return CustomGridLayoutManager.this.computeScrollVectorForPosition(targetPosition);
        }

        //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);
}
 
開發者ID:Old-Geek,項目名稱:Musique,代碼行數:25,代碼來源:CustomGridLayoutManager.java

示例13: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {

    if (position < 0) {
        return;
    }

    final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {

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

        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
    };

    linearSmoothScroller.setTargetPosition(position);
    startSmoothScroll(linearSmoothScroller);
}
 
開發者ID:toshiapp,項目名稱:toshi-android-client,代碼行數:24,代碼來源:SpeedyLinearLayoutManager.java

示例14: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView,
                                   RecyclerView.State state,
                                   int position) {
    RecyclerView.SmoothScroller smoothScroller =
            new LinearSmoothScroller(recyclerView.getContext()) {
                @Override
                public PointF computeScrollVectorForPosition(int targetPosition) {
                    return SnappyLinearLayoutManager.this
                            .computeScrollVectorForPosition(targetPosition);
                }

                @Override
                protected int getVerticalSnapPreference() {
                    return SNAP_TO_START; // override base class behavior
                }
            };
    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
 
開發者ID:hidroh,項目名稱:materialistic,代碼行數:21,代碼來源:SnappyLinearLayoutManager.java

示例15: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
    final LinearSmoothScroller linearSmoothScroller =
            new LinearSmoothScroller(recyclerView.getContext()) {

                // I want a behavior where the scrolling always snaps to the beginning of
                // the list. Snapping to end is also trivial given the default implementation.
                // If you need a different behavior, you may need to override more
                // of the LinearSmoothScrolling methods.
                protected int getHorizontalSnapPreference() {
                    return SNAP_TO_START;
                }

                protected int getVerticalSnapPreference() {
                    return SNAP_TO_START;
                }

                @Override
                public PointF computeScrollVectorForPosition(int targetPosition) {
                    return SnappyLinearLayoutManager.this
                            .computeScrollVectorForPosition(targetPosition);
                }
            };
    linearSmoothScroller.setTargetPosition(position);
    startSmoothScroll(linearSmoothScroller);
}
 
開發者ID:Luorrak,項目名稱:Ouroboros,代碼行數:27,代碼來源:SnappyLinearLayoutManager.java


注:本文中的android.support.v7.widget.LinearSmoothScroller類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。