【问题标题】:I am getting Error because of Floating button由于浮动按钮,我收到错误
【发布时间】:2019-06-24 17:59:22
【问题描述】:

在我的代码中,我在 XML 文件中使用数据绑定,但由于 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">
<data>
    <import type="android.view.View" />
    <variable
        name="userViewModel"
        type="com.example.projectdatabinding.viewModel.UserViewModel" />
</data>

   <android.support.v4.widget.DrawerLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorWhite"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">


            <ProgressBar
                android:id="@+id/progress_bar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:visibility="@{userViewModel.progressBar}" />

            <TextView
                android:id="@+id/label_status"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="@{userViewModel.messageLabel}"
                app:visibility="@{userViewModel.userLabel}" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/list_user"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/colorWhite"
                android:clipToPadding="false"
                android:scrollbars="vertical"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                app:visibility="@{userViewModel.userRecycler}"
                tools:listitem="@layout/item_user" />

        </LinearLayout>
        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="@dimen/fab_margin"
            android:clickable="true"
            android:onClick="@{userViewModel::onClickFabToLoad}"
            android:src="@drawable/ic_account_circle_24dp" />

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </android.support.design.widget.AppBarLayout>

    </android.support.design.widget.CoordinatorLayout>
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true" />

</android.support.v4.widget.DrawerLayout>

在 logcat 我收到这样的错误:

Binary XML file line #59: Binary XML file line #59: Error inflating class android.support.design.widget.FloatingActionButton

我的 gradle 文件是:

 implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.google.code.gson:gson:2.7'

implementation 'com.squareup.retrofit2:retrofit:2.2.0'
implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.2.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.0.5'
implementation 'de.hdodenhof:circleimageview:2.1.0'
implementation 'com.github.bumptech.glide:glide:3.7.0'

我看到了很多解决方案,比如 gradle 的变化

 implementation 'com.android.support:appcompat-v7:28.0.0' 

还有设计gradle

  implementation 'com.android.support:design:28.0.0'

我已经尝试了几乎所有 StackOverflow 的答案,但我无法成功,提前谢谢你

【问题讨论】:

  • 检查ic_account_circle_24dp是否存在于所有可绘制文件夹中,并验证图像是否损坏
  • 我已经改过了
  • 你在 res 中有单独的值文件夹吗?
  • @Redman 谢谢你,我无法识别那个时间,最后我在我的可绘制文件夹中看到它就像 (24v)
  • 好的,让我为未来的用户添加一个答案。

标签: android xml android-layout data-binding floating-action-button


【解决方案1】:

检查ic_account_circle_24dp 是否存在于所有可绘制文件夹中,并验证图像是否损坏。

添加抽屉时,Android 会自行创建几个文件夹,例如 drawable-v24。确保您也删除该文件夹。

【讨论】:

    猜你喜欢
    • 2018-10-21
    • 2020-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多