自定义ViewPager XML文件无法识别问题

来源:互联网 发布:iwatch软件排行 编辑:程序博客网 时间:2024/06/06 12:20

今天写了一个自定义的ViewPager,但是运行时报错
Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class com.mydrivernews.tools.NoScorllViewPager
意思是xml文件第13行这句话有错误

后台去xml可视化界面看了一下,发现报错
Custom view NoScorllViewPager is not using the 2- or 3-argument View constructors; XML attributes will not work

意思是缺少构造方法

后来去查了一下,自定义控件需要继承复写多个构造方法,下面是ViewPager需要写的构造方法,写下来纪录一下。

public class NoScorllViewPager extends ViewPager {

 public NoScorllViewPager(Context arg0,AttributeSet arg1) { // TODO Auto-generated constructor stub super(arg0, arg1); }public NoScorllViewPager(Context context) {    super(context);    // TODO Auto-generated constructor stub}

。。。
}

0 0