经过 研究 实现了自定义 键盘 ,支持随意拖动 和数字及其他字符输入
下面是主要的代码 和使用方法
import android.content.Context;
import android.util.Log;import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import com.only.onlybiapp.AppContext;
import com.only.onlybiapp.R;
import com.only.onlybiapp.interfaces.IKeyBoardListener;
// 这个是自定义的键盘控件
public class NumKeyBoardLinearLayout extends LinearLayout implements
View.OnClickListener, OnGestureListener {
private Context mContext;
private View v;
private Button button_numkeyboard_one;// 数字一
private Button button_numkeyboard_two;// 数字二
private Button button_numkeyboard_three;// 数字三
private Button button_numkeyboard_four;// 数字四
private Button button_numkeyboard_five;// 数字五
private Button button_numkeyboard_six;// 数字六
private Button button_numkeyboard_seven;// 数字七
private Button button_numkeyboard_eight;// 数字八
private Button button_numkeyboard_nine;// 数字九
private Button button_numkeyboard_comma;// 符号逗号
private Button button_numkeyboard_zero;// 数字零
private Button button_numkeyboard_point;// 符号点
private Button button_numkeyboard_scale;// 符号百分比
private Button button_numkeyboard_zeros;// 数字两个零
private Button button_numkeyboard_clear;// 清空
private Button button_numkeyboard_comfirm;// 确认
boolean isMoveEvent = false; // 是否是拖动输入法
private float startX = 0; // the first pointer index of x coordinate
private float startY = 0; // the first pointer index of Y coordinate
private float x;// the coordinate of X
private float y;// the coordinate of Y
private IKeyBoardListener iKeyBoardListener;
private final int fromLeft = -535; // 可以根据屏幕分辨率进行调整
private boolean isAdd = false;
GestureDetector detector;
public IKeyBoardListener getiKeyBoardListener() {
return iKeyBoardListener;
}
public void setiKeyBoardListener(IKeyBoardListener iKeyBoardListener) {
if (iKeyBoardListener != this.iKeyBoardListener) { // 换了一个editText
this.iKeyBoardListener = iKeyBoardListener;
}
}
private WindowManager wm = (WindowManager) getContext()
.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
private WindowManager.LayoutParams wmlp = AppContext.getLayoutParams();
public NumKeyBoardLinearLayout(Context context) {
super(context);
this.mContext = context;
initView();
initData();
setListener();
}
private void initView() {
v = View.inflate(mContext