Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓数据绑定视图标签是';视图上不正确:null_Android_Android Layout_Android Databinding - Fatal编程技术网

Android 安卓数据绑定视图标签是';视图上不正确:null

Android 安卓数据绑定视图标签是';视图上不正确:null,android,android-layout,android-databinding,Android,Android Layout,Android Databinding,问题标签在stackoverflow中可能很常见,但我这里有一些情况。我想实现我的应用程序将有一个底部菜单栏,它将在整个应用程序中可见。因此,我添加了一个视图,并将其设置在基本活动上,如下所示 @Override public void setContentView(int layoutResID) { fullLayout = (RelativeLayout) getLayoutInflater().inflate(R.layout.activity_base, null);

问题标签在stackoverflow中可能很常见,但我这里有一些情况。我想实现我的应用程序将有一个底部菜单栏,它将在整个应用程序中可见。因此,我添加了一个视图,并将其设置在基本活动上,如下所示

@Override
public void setContentView(int layoutResID) {
    fullLayout = (RelativeLayout) getLayoutInflater().inflate(R.layout.activity_base, null);
    configureToolbar(fullLayout);
    subActivityContent = (FrameLayout) fullLayout.findViewById(R.id.content_frame);
    getLayoutInflater().inflate(layoutResID, subActivityContent, true);
    super.setContentView(fullLayout);
}
以前是这样的:

@Override
public void setContentView(int layoutResID) {
    View view = getLayoutInflater().inflate(layoutResID, null);
    configureToolbar(view);
    super.setContentView(view);
}
现在在某些页面上有数据绑定。这被称为如下所示:

   viewModel = new MyViewModel(someId, someName, false, emptyString);
   binding = DataBindingUtil.setContentView(this, R.layout.activity_my_layout);
   binding.setItem(viewModel);
现在我在第二行遇到了错误

这是我的活动布局。第一个是公共布局,即活动库,第二个是数据绑定布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent">

<include android:id="@+id/app_bar" layout="@layout/app_bar" />

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<com.roughike.bottombar.BottomBar
    android:id="@+id/bottomBar"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:layout_alignParentBottom="true"
    app:bb_tabXmlResource="@xml/bottombar_tabs" />

第二布局:

<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:map="http://schemas.android.com/apk/res-auto">

<data>
    <import type="android.view.View" />

    <variable
        name="item"
        type="io.ppp.views.someActivity" />
</data>

<RelativeLayout
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/root_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="io.ppp.views.someActivity">

    <include  android:id="@+id/app_bar"  layout="@layout/app_bar" />
    <!--<include  layout="@layout/activity_base" />-->




    <WebView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webViewLoader"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />


    <RelativeLayout
        android:id="@+id/progress_indicator"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="false"
        android:layout_centerInParent="true"
        android:visibility="@{item.loading ? View.VISIBLE : View.GONE}">

        <ProgressBar
            android:id="@+id/search_progress"
            style="@style/Base.Widget.AppCompat.ProgressBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:indeterminate="true" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_gravity="center"
            android:layout_marginTop="50dp"
            android:text="@{item.loadingText}"
            android:textAppearance="?android:attr/textAppearanceSmall" />

    </RelativeLayout>

</RelativeLayout>


我认为这不是一个在应用程序中实现底部导航栏的好解决方案,因为您正在创建活动,用户很清楚,每次更改活动时,屏幕都会完全交换(包括底部导航栏)而不是在屏幕底部保留一个固定的元素,用户将使用它来引导自己浏览应用程序

在Android中实现底部导航比在iOS中要复杂得多,因为你必须使用一个单一的活动和片段(如果你有很多屏幕,那么就需要使用很多片段)来实现平滑的底部导航

我给您的建议是将活动转换为片段,使用底部栏和片段容器实现底部导航活动,然后从那里开始


从API 25开始,它引入了
BottomNavigationView
,这将使您的生活更加轻松,您不需要使用GitHub的
BottomBar
库。我还建议您查看
AHBottomNavigation
,在我看来,它比本地导航更完整,让您可以更好地控制和选择底部栏。

您好,感谢您的评论。在我的应用程序中,底部栏仅用于在两个页面之间交换,其余活动和导航将从上半部分开始。所以问题是,它不像完全依赖于选项卡的应用程序。这就是问题所在,即使是在两个单独的页面上也不适合这样做。您应该有一个单独的活动,带有一个片段容器,并在容器中交换视图,但是我的上级在项目中间引入底部栏,而项目模式不像它应该的那样构建。因此,如果有任何方法可以避免错误,这将是非常有帮助的。我还必须在我正在运行的项目中实现底部导航,我给你的建议是将你的活动转换为片段,并实现底部导航活动,该活动处理所有Swaps可能需要一段时间,但最终你会有一个更好的解决方案,而且你可以及时继续前进