最近要实现一个自定义scrollview,然后在完成后发现滑动时并不是预期的效果,检查了很多次代码都没有发现bug(确保ontouchevent()方法正确)
折腾了两个多小时,特此记录,以示后人
首先看一下系统一般自定义view时习惯写的构造函数
public Song(Context context) {
this(context,null);
}
public Song(Context context, AttributeSet attrs) {
this(context, attrs,0);
}
public Song(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray a =context.getTheme().obtainStyledAttributes(attrs, R.styleable.song, defStyleAttr, 0);