android 控件的移动
1.
Java代码
imagebutton.setOnTouchListener(newOnTouchListener(){
int[]postion=newint[]{0,0};
@Override
publicbooleanonTouch(Viewv,MotionEventevent){
intx=(int)event.getRawX();
inty=(int)event.getRawY();
intleft=v.getLeft();
inttop=v.getTop();
switch(event.getAction()){
caseMotionEvent.ACTION_DOWN:
postion[0]=(int)event.getX();
postion[1]=y-v.getTop();
break; caseMotionEvent.ACTION_MOVE:
v.layout(x-postion[0],y-postion[1],x+1024
-postion[0],y-postion[1]+768);
v.postInvalidate();
default:break;
}
returnfalse;
}
}
);
2.布局移动
Java代码
x=x+10;
y=y+10;
LayoutParamslayoutParams=mIconPinpu.getLayoutParams();
layoutParams.height=x;
layoutParams.width=y;
mIconPinpu.setLayoutParams(layoutParams);