android.view.InflateException:二进制XML文件行#39:错误膨胀类ProgressWidget

时间:2016-08-26 18:03:20

标签: android tablet seekbar inflate-exception

public final class ProgressWidget extends LinearLayout {

    <Default Constructors implemented> {
        setOrientation(LinearLayout.VERTICAL);
        inflate(context, R.layout.horizontal_progress, this);
    }

    @Override
    protected void onFinishInflate() {
        //Continue with rest of the logic.
    }
}

R.layout.horizo​​ntal_progress有35行。

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">

<TextView
    android:id="@+id/progressTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/rounded_white_background"
    android:gravity="center"
    android:textColor="@color/light_black"
    android:textSize="12sp"
    android:fontFamily="roboto-regular"
    android:paddingTop="1dp"
    android:paddingBottom="1dp"
    android:paddingLeft="2dp"
    android:paddingRight="2dp" />

<SeekBar
    android:id="@+id/progress"
    android:layout_width="match_parent"
    android:layout_height="@dimen/horizontal_progress_height"
    android:indeterminate="false"
    android:progressDrawable="@drawable/horizontal_progress"
    android:gravity="center"
    android:thumb="@null"
    android:progress="0"
    android:secondaryProgress="0"
    android:max="100"
    android:minHeight="@dimen/horizontal_progress_height"
    android:paddingTop="1dp"
    android:paddingBottom="1dp"
    android:paddingLeft="2dp"
    android:paddingRight="2dp" />

</merge>

R.drawable.horizo​​ntal_progress有36行。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
<item android:id="@android:id/background">
    <shape android:shape="rectangle" >
        <corners android:radius="@dimen/horizontal_progress_radius" />
        <gradient
            android:startColor="@color/horizontal_progress_background"
            android:endColor="@color/horizontal_progress_background"
            android:angle="270"/>
    </shape>
</item>
<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape android:shape="rectangle" >
            <corners android:radius="@dimen/horizontal_progress_radius" />
            <gradient
                android:startColor="@android:color/white"
                android:endColor="@android:color/white"
                android:angle="270"/>
        </shape>
    </clip>
</item>
<item android:id="@android:id/progress">
    <clip>
        <shape android:shape="rectangle" >
            <corners android:radius="@dimen/horizontal_progress_radius" />
            <gradient
                android:startColor="?android:attr/colorAccent"
                android:endColor="?android:attr/colorAccent"
                android:angle="270"
                tools:ignore="NewApi"/>
        </shape>
    </clip>
</item>
</layer-list>

Stack-trace的最后一段。

引起:android.view.InflateException:二进制XML文件行#39:错误膨胀类ProgressWidget                                                                       在android.view.LayoutInflater.createView(LayoutInflater.java:620)                                                                       在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)                                                                       在android.view.LayoutInflater.rInflate(LayoutInflater.java:755)                                                                       在android.view.LayoutInflater.rInflate(LayoutInflater.java:758)                                                                       在android.view.LayoutInflater.inflate(LayoutInflater.java:462)                                                                       在android.view.LayoutInflater.inflate(LayoutInflater.java:397)                                                                       在android.view.LayoutInflater.inflate(LayoutInflater.java:353)                                                                     在android.view.View.inflate(View.java:1746

一切正常在手机设备上 - 三星Galaxy S5 SM-G900A,Android 5.0版。在Asus Nexus 7,Android 4.4.3上始终与上面的堆栈跟踪崩溃。

此ProgressWidget是Android库模块的自定义可重用组件,将与项目模块一起使用。主要的项目模块预计将迎合minSDKVersion 16一直到TargetSDKVersion 24。

任何有关可能导致平板电脑设备崩溃的指示都将非常感激。

2 个答案:

答案 0 :(得分:0)

尝试更改最后一个渐变(具有tools:ignore="NewApi"行的渐变)中的颜色。这两种颜色未在SDK&lt; 21中定义。 如果这还没有解决,请发布更多的堆栈跟踪。

答案 1 :(得分:0)

I managed to resolve this issue based off another similar issue.

https://stackoverflow.com/a/39254876/941912