在SwipeRefreshLayout数据绑定Android上无法解析appbar_scrolling_view_behavior

时间:2019-04-23 09:03:12

标签: android-databinding android-coordinatorlayout android-appbarlayout swiperefreshlayout android-mvvm

我尝试将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提及“未解决的类'@ string / appbar_scrolling_view_behavior'少...(Ctrl + F1)检查信息:验证Android XML文件中的资源引用。” < / p>

1 个答案:

答案 0 :(得分:2)

改为使用此:

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