android.view.InflateException:二进制 XML 文件行(不存在)
android.view.InflateException: Binary XML file line (which doesn't exist)
我有这样的布局:
<?xml version="1.0" encoding="utf-8"?>
<merge>
<android.support.constraint.ConstraintLayout
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"
android:id="@+id/has_selected_account"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/account_display_name"
android:layout_width="wrap_content"
android:layout_marginTop="@dimen/account_menu_name_and_display_vertical_padding"
android:layout_marginBottom="@dimen/account_menu_name_and_display_vertical_padding"
app:layout_constraintBottom_toTopOf="@+id/account_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="DisplayNameIsLongSoItShouldBeTruncatedAtSomePoint"/>
<TextView
android:id="@+id/account_name"
android:layout_width="wrap_content"
android:layout_marginTop="@dimen/account_menu_name_and_display_vertical_padding"
android:layout_marginBottom="@dimen/account_menu_name_and_display_vertical_padding"
android:includeFontPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/account_display_name"
tools:text="emailisverylongaswellwewantittogettruncated@gmail.longdomain.com"/>
</android.support.constraint.ConstraintLayout>
</merge>
我得到一个非常普遍的 inflation 错误:
Caused by: android.view.InflateException: Binary XML file line #39: Error inflating class com.me.AccountParticle
at android.view.LayoutInflater.createView(Layo
(剪成这样)
我试图简化我的 XML。我该如何解决 inflation 错误?
加上我的布局 XML 不像 #39
那么这是指哪里呢?
您缺少 android:layout_height
两个 TextView
,这就是您如何获得视图 inflation 错误。当视图被膨胀时,它需要通过另一个 class 或方法来解析 merge
标记,这似乎有不同的解析错误的方式。否则你会看到一个更清晰的错误,缺少 android:layout_height
。
请使用这个。
<?xml version="1.0" encoding="utf-8"?>
<merge>
<android.support.constraint.ConstraintLayout
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"
android:id="@+id/has_selected_account"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/account_display_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/account_menu_name_and_display_vertical_padding"
android:layout_marginBottom="@dimen/account_menu_name_and_display_vertical_padding"
app:layout_constraintBottom_toTopOf="@+id/account_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="DisplayNameIsLongSoItShouldBeTruncatedAtSomePoint"/>
<TextView
android:id="@+id/account_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/account_menu_name_and_display_vertical_padding"
android:layout_marginBottom="@dimen/account_menu_name_and_display_vertical_padding"
android:includeFontPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/account_display_name"
tools:text="emailisverylongaswellwewantittogettruncated@gmail.longdomain.com"/>
</android.support.constraint.ConstraintLayout>
</merge>
我有这样的布局:
<?xml version="1.0" encoding="utf-8"?>
<merge>
<android.support.constraint.ConstraintLayout
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"
android:id="@+id/has_selected_account"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/account_display_name"
android:layout_width="wrap_content"
android:layout_marginTop="@dimen/account_menu_name_and_display_vertical_padding"
android:layout_marginBottom="@dimen/account_menu_name_and_display_vertical_padding"
app:layout_constraintBottom_toTopOf="@+id/account_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="DisplayNameIsLongSoItShouldBeTruncatedAtSomePoint"/>
<TextView
android:id="@+id/account_name"
android:layout_width="wrap_content"
android:layout_marginTop="@dimen/account_menu_name_and_display_vertical_padding"
android:layout_marginBottom="@dimen/account_menu_name_and_display_vertical_padding"
android:includeFontPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/account_display_name"
tools:text="emailisverylongaswellwewantittogettruncated@gmail.longdomain.com"/>
</android.support.constraint.ConstraintLayout>
</merge>
我得到一个非常普遍的 inflation 错误:
Caused by: android.view.InflateException: Binary XML file line #39: Error inflating class com.me.AccountParticle
at android.view.LayoutInflater.createView(Layo
(剪成这样)
我试图简化我的 XML。我该如何解决 inflation 错误?
加上我的布局 XML 不像 #39 那么这是指哪里呢?
您缺少 android:layout_height
两个 TextView
,这就是您如何获得视图 inflation 错误。当视图被膨胀时,它需要通过另一个 class 或方法来解析 merge
标记,这似乎有不同的解析错误的方式。否则你会看到一个更清晰的错误,缺少 android:layout_height
。
请使用这个。
<?xml version="1.0" encoding="utf-8"?>
<merge>
<android.support.constraint.ConstraintLayout
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"
android:id="@+id/has_selected_account"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/account_display_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/account_menu_name_and_display_vertical_padding"
android:layout_marginBottom="@dimen/account_menu_name_and_display_vertical_padding"
app:layout_constraintBottom_toTopOf="@+id/account_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="DisplayNameIsLongSoItShouldBeTruncatedAtSomePoint"/>
<TextView
android:id="@+id/account_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/account_menu_name_and_display_vertical_padding"
android:layout_marginBottom="@dimen/account_menu_name_and_display_vertical_padding"
android:includeFontPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/account_display_name"
tools:text="emailisverylongaswellwewantittogettruncated@gmail.longdomain.com"/>
</android.support.constraint.ConstraintLayout>
</merge>