本文整理匯總了Java中android.support.v7.widget.LinearSmoothScroller.SNAP_TO_START屬性的典型用法代碼示例。如果您正苦於以下問題:Java LinearSmoothScroller.SNAP_TO_START屬性的具體用法?Java LinearSmoothScroller.SNAP_TO_START怎麽用?Java LinearSmoothScroller.SNAP_TO_START使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.support.v7.widget.LinearSmoothScroller
的用法示例。
在下文中一共展示了LinearSmoothScroller.SNAP_TO_START屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onMarkerClick
@Override
public boolean onMarkerClick(Marker marker) {
if (marker.getTag() instanceof BusRouteStop) {
BusRouteStop stop = (BusRouteStop) marker.getTag();
if (stop != null) {
if (recyclerView != null) {
RecyclerView.SmoothScroller smoothScroller = new LinearSmoothScroller(getContext()) {
@Override protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
};
smoothScroller.setTargetPosition(Integer.parseInt(stop.sequence));
recyclerView.getLayoutManager().startSmoothScroll(smoothScroller);
}
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(Double.parseDouble(stop.latitude), Double.parseDouble(stop.longitude)), 16));
Intent intent = new Intent(getContext(), EtaService.class);
intent.putExtra(C.EXTRA.STOP_OBJECT, stop);
getContext().startService(intent);
}
}
return true;
}
示例2: onCreateView
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_read, container, false);
RecyclerView mRecyclerView = view.findViewById(R.id.versesRecyclerView);
mAdapter = new VersesAdapter();
mLayoutManager = mRecyclerView.getLayoutManager();
mRecyclerView.setAdapter(mAdapter);
//preload the versions
//new DBTRetriever().getBooks(getContext());
//new DBTRetriever().getVersions(getContext());
Activity activity = getActivity();
if (activity == null) {
return view;
}
mSmoothScroller = new LinearSmoothScroller(activity) {
@Override protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
};
mBookChapterView = activity.findViewById(R.id.selected_book);
mTranslationView = activity.findViewById(R.id.selected_translation);
setAppBarDisplay();
return view;
}
示例3: smoothScrollToPosition
public void smoothScrollToPosition(int position, final ScrollOptions options) {
final RecyclerView.SmoothScroller smoothScroller = new LinearSmoothScroller(this.getContext()) {
@Override
protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return ((LinearLayoutManager) this.getLayoutManager()).computeScrollVectorForPosition(targetPosition);
}
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
if (options.millisecondsPerInch != null) {
return options.millisecondsPerInch / displayMetrics.densityDpi;
} else {
return super.calculateSpeedPerPixel(displayMetrics);
}
}
@Override
public int calculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd, int snapPreference) {
int calc = super.calculateDtToFit(viewStart, viewEnd, boxStart, boxEnd, snapPreference);
if (options.viewPosition != null) {
int viewHeight = viewEnd - viewStart;
int boxHeight = boxEnd - boxStart;
float viewOffset = options.viewOffset != null ? PixelUtil.toPixelFromDIP(options.viewOffset) : 0;
float target = boxStart + (boxHeight - viewHeight) * options.viewPosition + viewOffset;
return (int) (target - viewStart);
} else {
return super.calculateDtToFit(viewStart, viewEnd, boxStart, boxEnd, snapPreference);
}
}
};
smoothScroller.setTargetPosition(position);
this.getLayoutManager().startSmoothScroll(smoothScroller);
}
示例4: smoothScrollToPosition
@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);
}
@Override
protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
//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);
}
示例5: 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);
}
示例6: scrollToPosition
public void scrollToPosition(int position) {
RecyclerView.SmoothScroller smoothScroller = new LinearSmoothScroller(getActivity()) {
@Override protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
};
smoothScroller.setTargetPosition(position);
nodeListView.getLayoutManager().startSmoothScroll(smoothScroller);
}
示例7: SnappingLinearLayoutManager
public SnappingLinearLayoutManager(Context context) {
this(context, LinearSmoothScroller.SNAP_TO_START);
}