当recyclerview放在scrollview / nestedScrollView中时,scrollToPosition方法不起作用

时间:2017-10-27 06:51:39

标签: android android-recyclerview android-scrollview android-nestedscrollview

在我的布局中,ScrollView是父级,其中Imageview(160dp高度)和Recyclerview为子级。 场景:有图像和10个String项列表,可见列表项是0,1,2,3,4。因此,只要有新的listitem,我就会更新列表并调用scrollToPosition方法(itemcount -1),但没有任何反应。我已经setNestedScrollEnabled(false)

我尝试scrollView.fullScroll(DOWN)方法scrollView.scrollTo(0, adapter.itemcount),使用此方法滚动到旧列表的最后一项,但不完全滚动显示添加的新项目。这是我的布局

<android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@null">

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/scrollView"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

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

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="140dp" />



                <View
                    android:id="@+id/grey_line"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/light_grey"
                    android:visibility="gone" />


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

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/comments_list"
                        android:focusable="true"
                        android:focusableInTouchMode="true"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:scrollbars="vertical" />


                </RelativeLayout>

            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>
    </android.support.v4.widget.SwipeRefreshLayout>

请帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

可能是你正在使用

android:descendantFocusability="blocksDescendants" 
在你的布局中

如果没有,请尝试使用

android:focusable="true"
android:focudeableInTouchMode="true"

Recyclerview

相关问题