首先,获取需要改变的Button 通过Button myButton = findviewById(R.id.xxx);之后有2种方式改变坐标第一种,带动画的改变
//位移动画 从左到右参数分别为
//x轴方向起始位置x差值 ,x轴方向结束位置x差值 , y轴方向起始位置y差值 ,y轴方向结束位置y差值
TranslateAnimation translateAnimation = new TranslateAnimation(fromXDelta,toXDelta,fromYDelta,toYDelta);
translateAnimation.setDuration(300); //设置动画世界
button.setAnimation(translateAnimation);上面的示例只是许多动画中的一种简单地位移动画,如果有兴趣可以查阅一下android动画方面的知识第二种,直接改变控件的位置
这种方法里面也有2种不用的情况//这是第一种 直接付给此button新的xy坐标
button.setX();
button.setY();
//这是第二种 让button有一个位移到指定地点
button.setTranslationX();
button.setTranslationY();第一种直接改变了xy坐标,第二种是添加了坐标位移但是控件本身的xy坐标还是在原来的位置