Android 自定义View
Android 自定义View
http://www.cnblogs.com/manuosex/p/5301252.html
https://www.jianshu.com/p/c84693096e41
OnTouchListener
OnGestureListener
private GestureDetector mGestureDetector;
public interface onDeleteListener {
void onDelete(int index);
}
public void setOnDeleteListener(OnDeleteListener listener) {
mOnDeleteListener = listener;
}
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
params.addRule(RelativeLayout.CENTER_VERTICAL);
private ViewGroup mItemLayout;
mItemLayout.removeView(mDeleteBtn);
mItemLayout = (ViewGroup) getChildAt(mSelectedItem
- getFirstVisiblePosition());
mItemLayout.addView(mDeleteBtn, params);
isDeleteShown = true;
onMeasure()
onLayout()
onDraw()
创建一个全新View实现自定义控件,无非分成这么几步:
Ⅰ、在OnMeasure()方法中,测量自定义控件的大小,使自定义控件能够自适应布局各种各样的需求。
Ⅱ、在OnDraw()方法中,利用哼哈二将(Canvas与Paint)来绘制要显示的内容。
Ⅲ、在OnLayout()方法中来确定控件显示位置。
Ⅳ、在OnTouchEvent()方法处理控件的触摸事件。
onDraw()
Canvas , Paint
onTouchEvent()