自定义的LinearLayout 使用报错 android.view.InflateException: Binary XML file line #3: Error inflating class
2016-03-17 17:48
633 查看
03-17 17:32:58.164 30209-30209/? E/AndroidRuntime: Process: tech.androidstudio.dispatchdemo, PID: 3020903-17 17:32:58.164 30209-30209/? E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{tech.androidstudio.dispatchdemo/tech.androidstudio.dispatchdemo.MainActivity}: android.view.InflateException:Binary XML file line #3: Error inflating class tech.androidstudio.dispatchdemo.RootLinearLayout03-17 17:32:58.164 30209-30209/? E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #3: Error inflating class tech.androidstudio.dispatchdemo.RootLinearLayout03-17 17:32:58.164 30209-30209/? E/AndroidRuntime: at tech.androidstudio.dispatchdemo.MainActivity.onCreate(MainActivity.java:11)03-17 17:32:58.164 30209-30209/? E/AndroidRuntime: at tech.androidstudio.dispatchdemo.MainActivity.onCreate(MainActivity.java:11)原因 :缺少构造方法:RootLinearLayout(Context context, AttributeSet attrs)
解决方法
添加构造方法:RootLinearLayout(Context context, AttributeSet attrs)
package tech.androidstudio.dispatchdemo;import android.content.Context;import android.util.AttributeSet;import android.util.Log;import android.view.MotionEvent;import android.widget.LinearLayout;/*** Created by Kodulf on 2016/3/17.*/public class RootLinearLayout extends LinearLayout {public RootLinearLayout(Context context) {super(context);}//TODO 一定不能缺少这个构造方法,不然会报错public RootLinearLayout(Context context, AttributeSet attrs) {super(context, attrs);}@Overridepublic boolean dispatchTouchEvent(MotionEvent ev) {int action = ev.getAction();switch (action){case MotionEvent.ACTION_DOWN:Log.d("Kodulf","RootLinearLayout ACTION_DOWN");break;}return super.dispatchTouchEvent(ev);}}
相关文章推荐
- 解决android studio Error:SSL peer shut down incorrectly
- android 图片缓存LruCache(二)
- Caused by: android.database.sqlite.SQLiteException: no such column:
- android开发 线程同步锁
- 我在华勤的那些日子-----------Android的laucher3源码剖析(一)
- Android新增API之AudioEffect中文API与应用实例
- WCF android调用
- textview 通过SpannableString 打开activity
- aandroid 不能墙时的下载镜像地址
- 关于Android程序杀掉之前所有Activity(可用于登陆后被顶掉、更改应用内语言)
- android 使用butterknife简化加载布局控件
- Android Gradle升级项目报错解决方法
- Android DrawerLayout的使用
- Android分享笔记(4) Android的webview加载本地html、本apk内html和远程URL
- android ImageLoader加载本地图片的工具类
- Android的StringBuffer的使用
- Android Studio中Git的安装配置以及使用
- Android初试--Android中的Service简介(1)
- Android拨打电话的方式
- Android循环创建控件