android自定义控件inflate报错view.inflate.exception
2014-07-16 17:31
435 查看
为了方便动态使用自定义KeyboardView, 对其进行了封装
但是每次在MainActivity中执行到加载的时候:
就会报错: view.inflate.exception, 首先发现在xml中自己直接使用了:
<KeyboardView /> 标签, 而androd有个自带的控件:
android.inputmethodservice.KeyboardView, 所以将xml中标签改成了:
但是问题依旧, 后来突然想到在重载FrameLayout的时候, 还有两个构造方法没有覆盖, 然后在代码中加上另外两个方法:
然后报错消失, 执行正常.
public class KeyboardView extends FrameLayout { private Context mcontext; public KeyboardView(Context context) { super(context); mcontext = context; initComponents(); } }
但是每次在MainActivity中执行到加载的时候:
keyboardView = (KeyboardView)stub.inflate();
就会报错: view.inflate.exception, 首先发现在xml中自己直接使用了:
<KeyboardView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="300dp" android:layout_gravity="bottom" >
<KeyboardView /> 标签, 而androd有个自带的控件:
android.inputmethodservice.KeyboardView, 所以将xml中标签改成了:
<com.yzh.lockpri2.widget.KeyboardView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="300dp" android:layout_gravity="bottom" >
但是问题依旧, 后来突然想到在重载FrameLayout的时候, 还有两个构造方法没有覆盖, 然后在代码中加上另外两个方法:
public class KeyboardView extends FrameLayout { private Context mcontext; public KeyboardView(Context context) { super(context); mcontext = context; initComponents(); } public KeyboardView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mcontext = context; initComponents(); } public KeyboardView(Context context, AttributeSet attrs) { super(context, attrs); mcontext = context; initComponents(); } }
然后报错消失, 执行正常.
相关文章推荐
- android自定义控件的创建和使用
- Android 实现自定义控件效果1
- Android中自定义控件
- android中使用自定义控件是报android.view.InflateException: Binary XML 异常
- Android应用之个人应用软件开发(4)【深度UI设计自定义控件】
- Android 自定义控件 eBook 翻书效果
- Android 自定义控件-SnakeLayout (仿gallery)
- android EditText里面嵌入两个按钮,通过按钮可以加减EditText里的数字,组合自定义控件。
- Android declare-styleable:自定义控件的属性(attr.xml,TypedArray)的使用
- Android 实现自定义控件效果2
- Android 自定义控件 eBook 翻书效果
- Android 自定义控件 eBook 翻书效果
- Android 自定义控件的 拖拽、移动 实现 方法
- Android 自定义控件 仿乐Phone UI
- 【转】Android自定义控件中自定义属性的处理方式
- android 自定义控件属性
- Android 自定义控件-SnakeLayout (仿gallery)
- android自定义控件的创建和使用
- [转]Android.自定义控件的实现
- Android自定义控件(2)