кратко опиши что делает каждый метод и когда его можно использовать : /* * Copyright…
- User
кратко опиши что делает каждый метод и когда его можно использовать : /*
- Copyright 2018 The Android Open Source Project
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
code
http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. */
package androidx.recyclerview.widget;
import android.util.DisplayMetrics; import android.view.View; import android.view.animation.DecelerateInterpolator; import android.widget.Scroller;
import androidx.annotation.NonNull; import androidx.annotation.Nullable;
/**
-
Class intended to support snapping for a {@link RecyclerView}.
-
SnapHelper tries to handle fling as well but for this to work properly, the
-
{@link RecyclerView.LayoutManager} must implement the {@link RecyclerView.SmoothScroller.ScrollVectorProvider} interface or
-
you should override {@link #onFling(int, int)} and handle fling manually. */ public abstract class SnapHelper extends RecyclerView.OnFlingListener {
static final float MILLISECONDS_PER_INCH = 100f;
RecyclerView mRecyclerView; private Scroller mGravityScroller;
// Handles the snap on scroll case. private final RecyclerView.OnScrollListener mScrollListener = new RecyclerView.OnScrollListener() { boolean mScrolled = false;
code@Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); if (newState == RecyclerView.SCROLL_STATE_IDLE && mScrolled) { mScrolled = false; snapToTargetExistingView(); } } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { if (dx != 0 || dy != 0) { mScrolled = true; } } };
- Assistant
Данный класс SnapHelper предназначен для поддержки снаппинга для RecyclerView. Он позволяет автоматически проскроллить RecyclerView таким образом, чтобы выбранный элемент оказался в видимой области. Краткое описание каждого метода: