android自定义控件inflate报错view.inflate.exception
来源:互联网 发布:淘宝服装ps教程 编辑:程序博客网 时间:2024/05/20 18:00
为了方便动态使用自定义KeyboardView, 对其进行了封装
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();}}
然后报错消失, 执行正常.
0 0
- android自定义控件inflate报错view.inflate.exception
- Android 自定义控件之inflate()
- 使用自定义控件报错:Error inflate class
- Android中View.inflate()
- inflate自定义attr报错的解决方法
- inflate自定义attr报错的解决方法
- 安卓自定义组合控件 android.view.InflateException: Binary XML file #23:error inflate
- Android自定义View开篇之(LayoutInflater.inflate()详解)
- android:打气筒功能View.inflate
- Android XML布局文件报错Unable to inflate view tag without class attribute
- Android:inflate.inflate()方法
- Exception:Unable to inflate view tag without class attribute(控件标签有问题)
- 从xml inflate自定义的View
- Android Inflate
- Android inflate
- inflate
- inflate
- inflate
- info.plist的选项含义
- cocos2d-x-3.2启用Box2d物理引擎
- 2014-7-16-表单提交(回调)
- Repeater 换行显示
- STL 源码剖析 算法 stl_algobase.h
- android自定义控件inflate报错view.inflate.exception
- 静态、动态库制作使用
- BZOJ 1901 动态第K大
- 程序员要注意的一些事
- OPENCV2.3.1在Win7+VC2010下的安装与配置
- 防火防盗防蹭网
- Tomcat启动报错:transport error 202: bind failed: Address already in use
- python日期操作
- 常用的正则表达式