【问题标题】:How to scroll whole activity如何滚动整个活动
【发布时间】:2019-09-17 09:52:52
【问题描述】:

我写了一个应用程序,主页是 LinearLayout 并且在 Fragment 中。在这个 LinearLayout 中有两个 RecyclerViews 和 SearchBar 等。我想滚动整个活动。我花了 2 天时间,但无法成功。我怎样才能以简单的方式做到这一点? LinearLayout 中有很多适配器和连接。我怎样才能在不破坏任何代码的情况下实现这一目标。 我想滚动整个活动。

提前致谢。

【问题讨论】:

标签: android android-layout android-recyclerview scrollview


【解决方案1】:

你只需添加这一行:

//java
yourRecyclerView.setLayouManager(new LinearLayoutManager(this));

//kotlin
yourRecyclerView.layoutManager = LinearLayoutManager(this)

或来自 xml:

 app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"

请注意,不仅有LinearLayoutManager。如果您使用的是 Grid RecyclerView,那么您可能想要使用 GridLayoutManager

【讨论】:

  • 感谢您的回答。错误消失了,但我现在看不到 LinearLayout 组件,它们也消失了。 LinearLayout 中有很多组件,但是当我将它们放入 RecyclerView 时,它们消失了。我该如何解决?提前致谢
  • 您能否更新问题以使其更清楚。我不太明白你说的是什么
【解决方案2】:

在xml中设置Scroll /NestedScrollView作为父视图滚动整个布局 在回收站视图中添加此属性以刷新回收站滚动 android:overScrollMode="never"

试试这个代码:

 <android.support.v4.widget.NestedScrollView
                    android:id="@+id/navigation_nested"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:fillViewport="true"
                    android:overScrollMode="never">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:padding="@dimen/margin_15">

                    <TextView
                        android:id="@+id/video_tv"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="@dimen/margin_15"
                        android:drawableLeft="@drawable/ic_video_tutorial"
                        android:drawablePadding="@dimen/margin_20"
                        android:fontFamily="@font/poppins"
                        android:paddingLeft="@dimen/text_15"
                        android:text="@string/videos"
                        android:textColor="@color/blackTextColor"
                        android:textSize="@dimen/text_15" />


                    <android.support.v7.widget.RecyclerView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:overScrollMode="never" />
                </LinearLayout>
            </android.support.v4.widget.NestedScrollView>

【讨论】:

    【解决方案3】:

    我解决了这个问题。 只需在LinearLayout 上写上ScrollView

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
        <LinearLayout>
          .....
        </LinearLayout>
    
    </ScrollView>
    

    【讨论】:

      猜你喜欢
      • 2020-10-07
      • 1970-01-01
      • 1970-01-01
      • 2017-08-28
      • 2016-02-08
      • 2016-04-16
      • 2016-08-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多