android 控件的移动

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);

网盘资源分享: http://pan.baidu.com/share/home?uk=1882162285

 

 

 

转载于:https://www.cnblogs.com/james1207/p/3329079.html

你可能感兴趣的:(android 控件的移动)