android - Android/Java:当 RecyclerView 可见性从 GONE 变为 VISIBLE 时如何禁用自动滚动
问题描述
RecyclerView
正如您在代码中看到的那样,我在 XML 文件中设置为已消失。
从服务器获取更新后,我想在设置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>
解决方案
启动活动时不要设置GONE使其默认为VISBILE。然后在回收站视图上加载数据,它不会回收
推荐阅读
- java - Java,如何编写或添加而不是覆盖文本文件?
- regex - Perl正则表达式捕获行首和行尾之间的字符串(行尾有一个空格)
- javascript - 运行此 jsp 页面时,我不断收到错误消息
- java - 如何修复 android studio 的所有/大多数依赖错误
- sql - 需要支持 Oracle 和 DB2 的通用日期函数
- python - 必须在某个点按两次 enter 才能运行 python
- c++ - 如何为在 x86 主机上为 arm 目标交叉编译的项目安装依赖项
- python - 如何在 python 中将 (10000, 10, 10) 数组转换为 (10000, 100, 1)?
- r - 从 PostgreSQL 查询日期/时间到 R
- flutter - 滚动/跳转到 Flutter GridView 中的正确位置