【问题标题】:Android error inflating class on xmlAndroid错误在xml上膨胀类
【发布时间】:2012-04-11 00:22:17
【问题描述】:

我创建了一个从 ViewFlipper 扩展的类。当我尝试在 xml 上实例化时,它给了我这个“错误在 xml 上膨胀类”

FixedViewFlipper

public FixedViewFlipper(Context context)
{
    super(context);
}

public FixedViewFlipper(Context context, AttributeSet attrs)
{
    super(context, attrs);
}

Xml

<View class="com.touchcare.idealogix.android.FixedViewFlipper"
    android:id="@+id/flipperAdd"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    >
</View>

Logcat

编辑:我在 MainActivity 中使用 TabActivity。

【问题讨论】:

  • 是您在视图类 xml 中指定的包中的 FixedViewFlipper 类吗?对不起,这就是我能从你的代码/logcat 中猜到的全部
  • package touchcare.idealogix.android; public class FixedViewFlipper extends ViewFlipper
  • 因此您不需要在 xml 中类定义的开头使用“com”
  • @L7ColWinters 是对的,但如果这不能解决问题,请尝试添加其他构造函数,例如:public FixedViewFlipper(Context context, AttributeSet attrs,int defStyle) { //something}
  • @Raykud 我看了一下,但似乎没有 ViewFlipper 的 defStyle,只有 Context 和 Context,AttributeSet。

标签: android xml user-interface view custom-controls


【解决方案1】:

你只需要 view 不被大写 -

<view 
    class="touchcare.idealogix.android.FixedViewFlipper"
    android:id="@+id/flipperAdd"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    >
</view>

这是完全有效的语法,并且在许多谷歌应用程序中都是这样做的

【讨论】:

  • Eclipse 自动完成方法说大写字母没问题:S
  • 仍然给我例外。
  • @Raykud eclipse 自动完成将您指向&lt;View/&gt;,它指的是Android 类View&lt;view class=""/&gt; 语法指向类型类的自定义视图。真的&lt;View /&gt;&lt;view class="com.android.view.View"/&gt; 的简写
  • 哦,谢谢你的信息。我很怀疑,因为我记得我之前遇到过这个问题并用下划线 V 修复了它,但想知道为什么 eclipse 让我变得更高。
  • 这对我很有帮助,我不知道你这样指定节点类。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-08
  • 2021-04-09
  • 2016-11-12
  • 2016-12-06
  • 1970-01-01
相关资源
最近更新 更多