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

时间:2016-08-14 07:44:08

标签: java android android-layout android-databinding android-studio-2.1

我的项目结构如下     我已将dataBinding { enabled true }添加到build.gradle (module app)     我已将classpath "com.android.databinding:dataBinder:1.0-rc4"添加到build.gradle(project)     我的活动的布局是activity_fullscreen.xml所以我尝试使用ActivityFullscreenBinding并且它带来了“无法解析符号”错误。有什么我需要导入。我正在使用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>

1 个答案:

答案 0 :(得分:0)

布局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的菜单重建您的项目:

  

构建 - &gt; RebuildProject。

会有错误:

  

错误:(34,40)标识符必须具有XML文件中的用户定义类型。 FabHandler错过了它

您可以通过添加data标记来解决此问题。 请参阅此文档。 https://developer.android.com/topic/libraries/data-binding/index.html