Android studio 2.1 数据绑定无法解析符号

Android studio 2.1 databinding cannot resolve symbol

我的项目结构如下 我已将 dataBinding { enabled true } 添加到 build.gradle (module app) 我已将 classpath "com.android.databinding:dataBinder:1.0-rc4" 添加到 build.gradle(project) 我的 activity 的布局是 activity_fullscreen.xml 所以我尝试使用 ActivityFullscreenBinding 但它带来了 "cannot resolve symbol" 错误。有什么我需要导入的吗?仅供参考,我正在使用 android studio 2.1 我已经在使用 gradle 2.1.0 这里是activity_fullscreen.xml

<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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@android:color/white"
    tools:context="com.roha.lungo.FullscreenActivity">

    <!-- The primary full-screen view. This can be replaced with whatever view
         is needed to present your content, e.g. VideoView, SurfaceView,
         TextureView, etc. -->

    <RelativeLayout
        android:background="@android:color/black"
        android:layout_width="match_parent"
        android:id="@+id/relativeLayout"
        android:layout_height="match_parent">

        <android.support.v4.view.ViewPager
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_height="wrap_content"></android.support.v4.view.ViewPager>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_margin="16dp"
            android:onClick="@{FabHandler::onBaseFabClick}"
            android:src="@drawable/ic_mic_black_24dp" />

        <LinearLayout
            android:id="@+id/fab_menu_one_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="12dp"
            android:layout_marginEnd="24dp"
            android:layout_marginRight="24dp"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:visibility="invisible"
            android:layout_alignParentRight="true"
            android:layout_above="@id/fab"
            >

            <TextView
                android:id="@+id/shareLabelTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:layout_marginRight="8dp"
                android:background="@drawable/circle_background_red"
                android:elevation="2dp"
                android:fontFamily="sans-serif"
                android:padding="5dip"
                android:text="Share"
                android:textColor="@android:color/white"
                android:typeface="normal" />


            <android.support.design.widget.FloatingActionButton
                android:id="@+id/shareFab"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:onClick="@{FabHandler::onShareFabClick}"
                android:tint="@android:color/white"
                fabSize="mini"
                srcCompat="@android:drawable/arrow_down_float"/>

        </LinearLayout>

        <LinearLayout
            android:id="@+id/fab_menu_two_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="24dp"
            android:layout_marginEnd="24dp"
            android:layout_marginRight="24dp"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:visibility="invisible"
            android:layout_alignParentRight="true"
            android:layout_above="@id/fab_menu_one_layout"
            >

            <TextView
                android:id="@+id/createLabelTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:layout_marginRight="8dp"
                android:background="@drawable/circle_background_red"
                android:elevation="2dp"
                android:fontFamily="sans-serif"
                android:padding="5dip"
                android:text="Create"
                android:textColor="@android:color/white"
                android:typeface="normal" />

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/createFab"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:onClick="@{FabHandler::onCreateFabClick}"
                android:tint="@android:color/white"
                app:fabSize="mini"
                app:srcCompat="@android:drawable/btn_star_big_on" />

        </LinearLayout>


    </RelativeLayout>

    <!-- This FrameLayout insets its children based on system windows using
         android:fitsSystemWindows. -->
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <RelativeLayout
            android:id="@+id/fullscreen_content_controls"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:orientation="horizontal"
            tools:ignore="UselessParent">

        </RelativeLayout>
    </FrameLayout>
</FrameLayout>

布局 xml 应由 layout 标记包裹。

你的activity_fullscreen.xml应该是这样的:

<layout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools">

    <FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:background="@android:color/white"
                 tools:context="com.roha.lungo.FullscreenActivity">
    ...
    </FrameLayout>

</layout>

然后从 AndroidStudio 的菜单中重建您的项目:

Build -> RebuildProject.

会出现错误:

Error:(34, 40) Identifiers must have user defined types from the XML file. FabHandler is missing it

您可以通过添加 data 标签来解决这个问题。 请参考这份文件。 https://developer.android.com/topic/libraries/data-binding/index.html