我正在使用数据绑定将视图绑定到活动,它工作正常,并且能够通过数据绑定对象访问视图,然后更新了布局文件并添加了更多视图,我再次构建了项目,但现在仍然无法得到我添加的新视图,它说不能解析符号。
我再次尝试构建该项目,但没有成功。
我尝试清理该项目,然后再次构建它没有用。
这是XML代码:
<?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"
tools:context=".DetailsActivity">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/backdrop_height"
android:background="@color/textColorPrimaryLight">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:collapsedTitleTextAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="@dimen/dimen_title_text_margin_start"
app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax">
<ImageView
android:id="@+id/movieBackdrop_iv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/image_placeholder_content_description"
android:scaleType="centerCrop"
app:srcCompat="@drawable/picture_placeholder" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/scrim" />
</FrameLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/app_bar_detail_activity"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:contentInsetStart="@dimen/dimen_inset_start"
app:layout_collapseMode="pin"
app:navigationIcon="@drawable/arrow_back_white" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<ImageView
android:elevation="10dp"
android:contentDescription="@string/image_placeholder_content_description"
android:id="@+id/moviePoster_iv"
android:layout_marginTop="160dp"
android:layout_marginStart="16dp"
android:layout_width="@dimen/small_poster_width"
android:layout_height="@dimen/small_poster_height" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</android.support.constraint.ConstraintLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
</layout>
最佳答案
数据绑定字段将与您的ID不同。 ID在snake_case中给出,最后您将通过camelCase获得ID字段
例如,如果您设置ID为movieBackdrop_iv
,则可以使用mBinding.movieBackdropIv
。
使用建议,而不仅仅是复制粘贴。
更新资料
我也遇到像您这样的问题,只需使用清理,重建或仅运行项目来获取布局中新添加的ID和变量。