appbar_scrolling_view_behavior未在SwipeRefreshLayout数据绑定中解决(android)。

4

我尝试将app:layout_behavior="@string/appbar_scrolling_view_behavior"添加到SwipeRefreshLayout中,但我不知道为什么在XML布局中它无法解决,尽管在运行代码后它可以正常工作。这是否与数据绑定和MVVM有关?


<?xml version="1.0" encoding="utf-8"?>
<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">

    <data>

        <variable
            name="viewModel"
            type="ir.basamadazmanovin.heartrate.ui.main.home.HomeViewModel" />
    </data>

    <androidx.coordinatorlayout.widget.CoordinatorLayout

        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:id="@+id/swipe_refresh_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:onRefreshListener="@{()-> viewModel.onRefresehing()}"
            app:refreshing="@{viewModel.isLoading}">


            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/fragment_home_recyclerView"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
                app:spanCount="3" />

        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/fragment_home_toolbar"
                style="@style/Toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:subtitleTextColor="@color/material_white"
                app:title="@string/app_name"
                app:titleTextAppearance="@style/Toolbar.TitleText"
                app:titleTextColor="@color/material_white" />
        </com.google.android.material.appbar.AppBarLayout>


    </androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>




implementation "com.google.android.material:material:1.0.0"

app:layout_behavior="@string/appbar_scrolling_view_behavior" 是红色的,并且IDE提示 "Unresolved class '@string/appbar_scrolling_view_behavior' less... (Ctrl+F1) Inspection info: Validates resource references inside Android XML files."

1个回答

3

使用这个替代:

            app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接