gpt4 book ai didi

android - ViewPager 中的 RecyclerView 不会滚动

转载 作者:行者123 更新时间:2023-12-04 23:54:24 25 4
gpt4 key购买 nike

在我的应用程序中,我有我的主页,其中有一个 ViewPager。我可以使用抽屉布局在 ViewPager 中的 fragment 之间导航。其中一个 fragment 是 RecyclerView(在 FrameLayout 中)。问题是我无法滚动 RecyclerView。

我之前问过一个问题,得到了解决方案,只是它是一个ScrollView而不是RecyclerView,并且ViewPager在一个ConstraintLayout中,现在它必须在一个RelativeLayout中,这样drawerLayout才能存在.

布局代码:

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/mainScreenContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
tools:context=".MainActivity">


<include
android:id="@+id/mainToolbar"
layout="@layout/main_toolbar_layout" />

<com.google.android.material.tabs.TabLayout
android:id="@+id/mainTabLayout"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="gone">

<com.google.android.material.tabs.TabItem
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="0dp" />

<com.google.android.material.tabs.TabItem
android:id="@+id/activeGoals"
android:layout_width="match_parent"
android:layout_height="0dp" />

<com.google.android.material.tabs.TabItem
android:id="@+id/achievedGoals"
android:layout_width="match_parent"
android:layout_height="0dp" />

<com.google.android.material.tabs.TabItem
android:id="@+id/stats"
android:layout_width="match_parent"
android:layout_height="0dp" />

<com.google.android.material.tabs.TabItem
android:id="@+id/tipsAndTricks"
android:layout_width="match_parent"
android:layout_height="0dp" />

<com.google.android.material.tabs.TabItem
android:id="@+id/aboutUs"
android:layout_width="match_parent"
android:layout_height="0dp" />

</com.google.android.material.tabs.TabLayout>

<androidx.viewpager.widget.ViewPager
android:id="@+id/mainViewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_below="@id/mainToolbar"/>

<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_below="@id/mainToolbar">

<com.google.android.material.navigation.NavigationView
android:id="@+id/list_nav_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/menu_items" />


</androidx.drawerlayout.widget.DrawerLayout>



</RelativeLayout>

fragment_active_goals.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
tools:context=".ActiveGoals">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/activeGoalsRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</FrameLayout>

我希望 RecyclerView 可以滚动。提前致谢(:

最佳答案

我也有同样的问题。在你定义你的 recyclerView.adapter

写这个

ViewCompat.setNestedScrollingEnabled(recyclerView, false);

我希望这对其他人有用

关于android - ViewPager 中的 RecyclerView 不会滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57243019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com