如何滚动整个 activity
How to scroll whole activity
我写了一个应用,主页是LinearLayout,在Fragment中。在这个 LinearLayout 中有两个 RecyclerViews 和 SearchBar 等。我想滚动整个 activity。我花了 2 天时间,但无法成功。我怎样才能轻松做到这一点? LinearLayout 中有很多适配器和连接。我怎样才能在不破坏任何代码的情况下实现这一目标。
我想滚动整个 activity.
提前致谢。
您只需添加此行:
//java
yourRecyclerView.setLayouManager(new LinearLayoutManager(this));
//kotlin
yourRecyclerView.layoutManager = LinearLayoutManager(this)
或来自xml:
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
请注意,不仅有 LinearLayoutManager
。如果您使用的是网格 RecyclerView
,那么您可能想要使用 GridLayoutManager
我解决了这个问题。
只需在 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>
在 xml 中将 Scroll /NestedScrollView 设置为父视图以滚动整个布局
在回收器视图中添加此属性以 flase 回收器滚动 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>
我写了一个应用,主页是LinearLayout,在Fragment中。在这个 LinearLayout 中有两个 RecyclerViews 和 SearchBar 等。我想滚动整个 activity。我花了 2 天时间,但无法成功。我怎样才能轻松做到这一点? LinearLayout 中有很多适配器和连接。我怎样才能在不破坏任何代码的情况下实现这一目标。 我想滚动整个 activity.
提前致谢。
您只需添加此行:
//java
yourRecyclerView.setLayouManager(new LinearLayoutManager(this));
//kotlin
yourRecyclerView.layoutManager = LinearLayoutManager(this)
或来自xml:
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
请注意,不仅有 LinearLayoutManager
。如果您使用的是网格 RecyclerView
,那么您可能想要使用 GridLayoutManager
我解决了这个问题。
只需在 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>
在 xml 中将 Scroll /NestedScrollView 设置为父视图以滚动整个布局 在回收器视图中添加此属性以 flase 回收器滚动 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>