【发布时间】:2019-07-28 16:50:25
【问题描述】:
在我的应用程序中,我有我的主页,其中有一个 ViewPager。我可以使用抽屉布局在 ViewPager 中的片段之间导航。其中一个片段是 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 可以滚动。在此先感谢(:
【问题讨论】:
-
只是为了确认,请您删除 DrawerLayout 只是为了测试,然后尝试 RecyclerView 仍然不可滚动
-
尝试将您的 ViewPager layout_height 更改为“match_parent”
-
@GiddyNaya 试过了,没有解决问题。
标签: android android-layout android-fragments android-recyclerview android-viewpager