我在XML文件中设置了RecyclerView
,正如您在代码中看到的那样。
从服务器获取更新后,我想要显示它们,当我将RecyclerView
可见性从GONE
设置为VISIBLE
时,它将向下滚动所有页面以到达此RecyclerView
。
我如何解决这个问题或者这个问题有没有更好的解决方案来使用ShimmerLayout
和RecyclerView`的而不发生这种情况。
这是我的代码的一部分:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
// Some rows are here
// ...
<LinearLayout
android:id="@+id/news_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical">
// Another Row
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/latest_news_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:nestedScrollingEnabled="false"
android:visibility="gone" />
<LinearLayout
android:id="@+id/news_shimmer_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical"
android:visibility="visible">
<include layout="@layout/shimmer_news_row" />
<include layout="@layout/shimmer_news_row" />
<include layout="@layout/shimmer_news_row" />
<include layout="@layout/shimmer_news_row" />
<include layout="@layout/shimmer_news_row" />
<include layout="@layout/shimmer_news_row" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
发布于 2021-05-10 18:19:29
不要在启动activity时设置GONE,默认情况下设置为VISBILE。则数据加载到回收器视图将不会回收
发布于 2022-02-28 11:25:16
我通过用nestedscrollview包装回收视图解决了这个问题。
<androidx.core.widget.NestedScrollView
android:id="@+id/layout_recycler_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</androidx.core.widget.NestedScrollView>
https://stackoverflow.com/questions/67467337
复制相似问题