首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android/Java:当RecyclerView可见性从可见变为可见时如何禁用自动滚动

Android/Java:当RecyclerView可见性从可见变为可见时如何禁用自动滚动
EN

Stack Overflow用户
提问于 2021-05-10 16:40:12
回答 2查看 47关注 0票数 0

我在XML文件中设置了RecyclerView,正如您在代码中看到的那样。

从服务器获取更新后,我想要显示它们,当我将RecyclerView可见性从GONE设置为VISIBLE时,它将向下滚动所有页面以到达此RecyclerView

我如何解决这个问题或者这个问题有没有更好的解决方案来使用ShimmerLayout和RecyclerView`的而不发生这种情况。

这是我的代码的一部分:

代码语言:javascript
运行
复制
<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>
EN

回答 2

Stack Overflow用户

发布于 2021-05-10 18:19:29

不要在启动activity时设置GONE,默认情况下设置为VISBILE。则数据加载到回收器视图将不会回收

票数 1
EN

Stack Overflow用户

发布于 2022-02-28 11:25:16

我通过用nestedscrollview包装回收视图解决了这个问题。

代码语言:javascript
运行
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67467337

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档