我正在使用API 8进行编码.
我需要从View中获取坐标X和Y,并将它们设置为新Button的坐标.
我试过不同的方法但没有任何作用......
setX和getX方法仅适用于api级别11,我需要一种方法在API8上执行此操作.
这是我的方法,允许创建一个按钮的可拖动副本(此副本是一个imageview,当我删除它成为一个新按钮)
public boolean dragCopy(View view, MotionEvent me, Button bt){
int x,y,w,h,id,t,l;
int cont=-1;
int coord[] = new int[2];
bt2=new Button(this);
id = bt.getId();
bt2.setId(id);
Resources res = getResources();
cont = FindCont(bt, vector);
dr = getLetter(bt, dr, res, vector, cont);
w=dr.getIntrinsicWidth();
h=dr.getIntrinsicHeight();
if (me.getAction() == MotionEvent.ACTION_DOWN) {
//clicked on the button. DRAG START
status = START_DRAGGING;
image = new ImageView(this);
//set image drawable
image.setImageDrawable(dr);
image.setPadding((int)bt.getLeft(),(int)bt.getTop(), 0, 0);
layout.addView(image, params);
}
if (me.getAction() == MotionEvent.ACTION_UP) {
//button …Run Code Online (Sandbox Code Playgroud)