【发布时间】:2021-06-25 10:00:18
【问题描述】:
我有一个带有导航视图的布局,其中抽屉布局作为父级。然后我有其他视图的线性布局,包括滑动刷新布局和回收器视图:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawer_layout"
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"
tools:context=".activities.MainActivity"
android:orientation="vertical"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_main_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/black"/>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_main_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:headerLayout="@layout/nav_header_layout"
app:menu="@menu/nav_main_layout"
android:layout_gravity="start"/>
</androidx.drawerlayout.widget.DrawerLayout>
问题是加载图标出现但永远不会消失,即使我编写代码让它消失:
swipeRefreshLayout.setOnRefreshListener(object : SwipeRefreshLayout.OnRefreshListener{
override fun onRefresh() {
Toast.makeText(this@MainActivity, "Swiped", Toast.LENGTH_SHORT).show()
swipeRefreshLayout.isRefreshing = false
}
})
连吐司消息都没有出现。
我的代码或 xml 有什么问题?
【问题讨论】:
-
向我们展示完整代码或最大代码,我们可以看到从变量到 id 的完整初始化
-
对不起,我不明白,我使用 kotlin 合成绑定,所以我不需要初始化变量,如果这就是你的意思
标签: android android-recyclerview swiperefreshlayout