【问题标题】:SwipeRefreshLayout showing no conent and not able to refresh somethinSwipeRefreshLayout 不显示任何内容并且无法刷新某些内容
【发布时间】:2020-02-08 14:31:09
【问题描述】:

当我尝试将 SwipeRefreshLayout 与 BottomAppBar 一起使用时,片段不显示任何内容,并且 SwipeRefresh 功能不存在。我还在 TopAppBar 的正常活动中实现了它,并且它工作正常。然而,当我使用 BottomAppBar 时,对我没有任何帮助。我已经花了几个小时试图解决这个问题。

我已经尝试过: Link1 Link2

感谢您的帮助!

我的代码:

活动

<androidx.drawerlayout.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".ui.main.MainActivity">


        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <androidx.core.widget.NestedScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <fragment
                    android:id="@+id/nav_host_main"
                    android:name="androidx.navigation.fragment.NavHostFragment"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:defaultNavHost="true"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:navGraph="@navigation/main_navigation" />
            </androidx.core.widget.NestedScrollView>

            <com.google.android.material.bottomappbar.BottomAppBar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                app:menu="@menu/main"
                app:hideOnScroll="true"
                app:navigationIcon="@drawable/ic_menu_24dp" />


        </androidx.coordinatorlayout.widget.CoordinatorLayout>


        <com.google.android.material.navigation.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>

Fragment:也用T试了一下

<androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/homeFragmentLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">


    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/refresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Test" />
        </RelativeLayout>
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

结果:

【问题讨论】:

    标签: android android-layout android-appbarlayout


    【解决方案1】:

    找到了解决办法: 问题是 nav_host_fragment 在 NestedScrollView 中。 SwipeToRefreshLayout 不能在另一个 ScrollView 中的滚动视图中。

            <androidx.coordinatorlayout.widget.CoordinatorLayout
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent">
    
    
                <fragment
                    android:id="@+id/nav_host_main"
                    android:name="androidx.navigation.fragment.NavHostFragment"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:defaultNavHost="true"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:navGraph="@navigation/main_navigation" />
    
    
                <com.google.android.material.bottomappbar.BottomAppBar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    app:menu="@menu/main"
                    app:hideOnScroll="true"
                    app:navigationIcon="@drawable/ic_menu_24dp" />
    
    
            </androidx.coordinatorlayout.widget.CoordinatorLayout>
    
    
            <com.google.android.material.navigation.NavigationView
                android:id="@+id/nav_view"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                android:fitsSystemWindows="true"
                app:headerLayout="@layout/nav_header_main"
                app:menu="@menu/activity_main_drawer" />
        </androidx.drawerlayout.widget.DrawerLayout>
    

    【讨论】:

      猜你喜欢
      • 2014-07-02
      • 2019-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-07
      • 2021-04-23
      • 2021-08-09
      • 2020-12-10
      相关资源
      最近更新 更多