2

我正在实现 etsy 在 github 上为 StaggeredGrid https://github.com/etsy/AndroidStaggeredGrid提供的库。我得到的错误是布局 activity_svg.xml 的 InflationException

<com.etsy.android.grid.StaggeredGridView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:item_margin="8dp"
app:column_count="@integer/grid_column_count" />

android.view.InflationException Binary XML File Line#3 Error inflating class com.etsy.android.grid.StaggeredGridView 根据之前与问题相关的答案,我检查了构造函数:

 public StaggeredGridView(final Context context) {
    this(context, null);
}

public StaggeredGridView(final Context context, final AttributeSet attrs) {
    this(context, attrs, 0);
}

public StaggeredGridView(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);

根据之前的回答,我还检查了文件是否在这个库中。那么 InflationException 还有什么问题呢?为什么班级没有膨胀?

如果您希望我添加更多代码部分,请发表评论。

4

1 回答 1

0

If you have custom controls in your application then it should be specified using the full package in your layout XML, if only "yourcustomcontrol" is used it will throw this error. For example:

<yourcustomcontrol android:id="@+id/yourCustomControl1" /> will throw error.
<packageName.yourcustomcontrol android:id="@+id/yourCustomControl1" />

will work. More about custom controls can be found at the android developers' homepage here

Originally answered here.

于 2014-09-08T16:23:47.397 回答