写于 2015 年 12 月 21 日

错误信息:

Binary XML file line #xxx: Error inflating class...

  • 引用类名问题:在Hello包下自定义了一个MineView,将他用于布局文件中,完整报名来进行引用。
    Hello.MineView

  • 构造函数问题:自定义一个View,必须派生实现基类View的三个构造函数
    View(Context context)

    View(Context context, AttributeSet attrs)

    View(Context context, AttributeSet attrs, int defStyle)

    从文档上的介绍来看,第二个和第三个构造函数对于XML这种引用方式是必须实现的,这三个构造函数应该是在不同的应用场合来实例化一个View对象。

  • 编译的中间文件没有清理干净:第三种就是你在原生系统代码的编译环境下编译APK之后,修改了XML,出现标题所述现象,clean build 即可。

  • 找不到资源文件:找不到drawable的资源文件,把drawablehdpi等文件夹的图片资源都拷贝一份到drawble下,问题解决。(网上查询出,默认情况下,编译时 drawable 会选用mdip的,具体没去研究,验证过)。

  • attr color 引用 报错,https://code.google.com/p/android/issues/detail?id=26251
    Androidbugcolor 无法被引用到drawable中,只能一个主题一个 drawable,5.0以上修复此bug?attr/white 是无法被引用的,只能 `@color/white

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <corners android:radius="2dp" />
    <solid android:color="?attr/white"/>`