相关疑难解决方法(0)

(平滑)ScrollToPosition与RecyclerView无法正常工作

我正在使用基本的RecyclerView和GridLayoutManager.我观察到,smoothScrollToPosition和scrollToPosition也没有正常工作.

a)使用时smoothScrollToPosition我经常收到错误RecyclerView

"RecyclerView:平滑滚动时传递到目标位置."

并且RecyclerView没有正确滚动(通常它会错过目标行).这主要是在我试图滚动到某行的第一项时

b)使用scrollToPosition它时似乎工作得很好但是大多数时候我只能看到行的第一项而其余的都没有显示.

你能给我一些提示,如何正确地完成至少一种方法吗?

非常感谢!

android scroll smooth-scrolling gridlayoutmanager android-recyclerview

48
推荐指数
5
解决办法
6万
查看次数

Android RecyclerView 的平滑滚动不适用于初始滚动

我正在开发一款仅在一台运行 KitKat 的设备上运行的 Android 应用程序。

我使用的 RecylerView 的平滑滚动功能在其他物理平板电脑上运行,但 genymotion 不幸的是在它需要运行的一台设备上停止运行。

它不是滚动到某个位置,而是越过目标位置并一直滚动到底部,看起来非常糟糕。

我能够追踪 RecyclerView 类中抽象 SmoothScroller 的错误。

           if (getChildPosition(mTargetView) == mTargetPosition) {
                onTargetFound(mTargetView, recyclerView.mState, mRecyclingAction);
                mRecyclingAction.runIfNecessary(recyclerView);
                stop();
            } else {
                Log.e(TAG, "Passed over target position while smooth scrolling.");
                mTargetView = null;
            }
Run Code Online (Sandbox Code Playgroud)

我使用的是我在网上找到的 SnappingLinearLayoutManager,但将其换成了 Android 中的普通 LinearLayoutManager,但仍然遇到同样的问题。

该列表有 7 个项目长(用户一次可以看到 4 个项目),我滚动到第 5 个项目(位置 4)。

当我滚动到第三个时,我没有收到此错误。

此外,在我上下滚动列表一次后,错误就停止发生。

编辑: 我可以使用layoutManager.scrollToPositionWithOffset(); 但我正在尝试用平滑的滚动动画来做到这一点。

这是我的一些代码和详细信息:

private void setupMainRecyclerViewWithAdapter() {
    mainLayoutManager = new SnappingLinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    mainListRecyclerView.setLayoutManager(mainLayoutManager);

    settingsMainListAdapter = new SettingsListAdapter(SettingsActivity.this,
            settingsPresenter.getSettingsItems(),
            settingsPresenter);

    mainListRecyclerView.setAdapter(settingsMainListAdapter);

    mainListRecyclerView.addItemDecoration(new BottomOffsetDecoration(EXTRA_VERTICAL_SCROLLING_SPACE)); …
Run Code Online (Sandbox Code Playgroud)

android android-scroll android-recyclerview linearlayoutmanager

2
推荐指数
1
解决办法
6740
查看次数

滚动到NestedScrollView中的recyclerview中的位置?

没有NestedScrollView可以使用,但是当我使用该滚动到无法使用RecyclerView的位置时

下面是xml代码;

<android.support.design.widget.CoordinatorLayout     
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/co_ordinate_layout"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@color/light_gray">

 <android.support.v4.widget.NestedScrollView    
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_marginTop="@dimen/dimen_55"
  android:fillViewport="true">
<LinearLayout
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="blocksDescendants"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:focusableInTouchMode="true"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/img_resturant"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:background="@drawable/products_offers"
                android:scaleType="fitXY" />

            <LinearLayout
                android:id="@+id/llTransparent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/dimen_20"
                android:focusableInTouchMode="true"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/tvRestaurantName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="@dimen/dimen_15"
                    android:textColor="@color/white"
                    android:textSize="@dimen/sp_20" />

                <TextView
                    android:id="@+id/tvAddress"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_gravity="center"
                    android:layout_toRightOf="@+id/ivTime"
                    android:textColor="@color/white"
                    android:textSize="@dimen/sp_14" />


                <TextView
                    android:id="@+id/tvTime"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_gravity="center"
                    android:textColor="@color/white"
                    android:textSize="@dimen/sp_14" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="0.5dp"
                    android:layout_marginLeft="@dimen/_20sdp"
                    android:layout_marginRight="@dimen/_20sdp"
                    android:layout_marginTop="@dimen/_10sdp"
                    android:background="@color/white" />

                <LinearLayout
                    android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android android-studio android-recyclerview

0
推荐指数
1
解决办法
2148
查看次数