【发布时间】:2018-04-08 17:03:01
【问题描述】:
在我的布局中,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>
请帮忙,谢谢!
【问题讨论】:
-
你得到这个问题的答案了吗??我也面临同样的问题......如果你明白了,请告诉我。
标签: android android-recyclerview android-scrollview android-nestedscrollview