本文整理匯總了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);
}
示例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);
}
示例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);
}
示例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;
}
};
}
示例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;
}
};
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}