本文整理匯總了Java中android.support.v7.widget.LinearSmoothScroller.setTargetPosition方法的典型用法代碼示例。如果您正苦於以下問題:Java LinearSmoothScroller.setTargetPosition方法的具體用法?Java LinearSmoothScroller.setTargetPosition怎麽用?Java LinearSmoothScroller.setTargetPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.LinearSmoothScroller
的用法示例。
在下文中一共展示了LinearSmoothScroller.setTargetPosition方法的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: 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);
}
示例5: 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);
}
示例6: 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);
}
示例7: 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);
}
示例8: 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
}
}
示例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 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);
}
示例10: 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);
}
示例11: 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);
}
示例12: smoothScrollToPosition
import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
@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);
}
示例13: smoothScrollToPositionWithAlignment
import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
public void smoothScrollToPositionWithAlignment(Context context, int position, final int scrollAlignment) {
if (!isAttachedToWindow()) {
// NOTE: startSmoothScroll() references mRecyclerView and it will crash when RecyclerView
// is not attached to LayoutManager.
scrollToPositionWithAlignment(position, scrollAlignment);
return;
}
LinearSmoothScroller linearSmoothScroller = new CenterAwareLinearSmoothScroller(context, scrollAlignment) {
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
prepareLayoutProvider();
Point targetScrollOffset = calculateScrollOffsetToShowPositionIfPossible(targetPosition, scrollAlignment);
if (targetScrollOffset == null) return null;
normalizeScrollOffset(targetScrollOffset);
return ScrollHelper.calculateUnitVectorFromPoints(mCurrentScrollOffset, targetScrollOffset);
}
};
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) {
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);
}
示例15: smoothScrollToPosition
import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
position = Math.max(position, 0);
position = Math.min(position, self.getItemCount());
/*
* LinearSmoothScroller's default behavior is to scroll the contents until
* the child is fully visible. It will snap to the top-left or bottom-right
* of the parent depending on whether the direction of travel was positive
* or negative.
*/
LinearSmoothScroller scroller = new LinearSmoothScroller(recyclerView.getContext()) {
/*
* LinearSmoothScroller, at a minimum, just need to know the vector
* (x/y distance) to travel in order to get from the current positioning
* to the target.
*/
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
int oldScrollX = self.getState().scrolledX;
int oldScrollY = self.getState().scrolledY;
self.getState().scrolledX = self.getState().itemsFrames.get(targetPosition).left;
self.getState().scrolledY = self.getState().itemsFrames.get(targetPosition).top;
self.fixScrollOffset();
int newScrollX = self.getState().scrolledX;
int newScrollY = self.getState().scrolledY;
self.getState().scrolledX = oldScrollX;
self.getState().scrolledY = oldScrollY;
return new PointF(newScrollX - oldScrollX, newScrollY - oldScrollY);
}
};
scroller.setTargetPosition(position);
self.startSmoothScroll(scroller);
}