我正在使用此代码在屏幕上移动图像(brickimg)。
//This makes the brick move
int x=brickimg.getRight()-brickimg.getLeft();
int y=brickimg.getBottom()-brickimg.getTop();
final TranslateAnimation translate = new TranslateAnimation(
Animation.ABSOLUTE,x, Animation.ABSOLUTE,
x, Animation.ABSOLUTE,y,
Animation.ABSOLUTE,1000);//How far it goes
translate.setDuration(450);//speed of the animation
translate.setFillEnabled(true);
translate.setFillAfter(true);
brickimg.startAnimation(translate);
它只使图像在y轴上移动,但我试图让它在x轴上移动。我已经改变了一些变量,看看是否会改变它,但事实并非如此。有谁知道如何让它在x轴上移动?
答案 0 :(得分:3)
你对fromX和toX使用相同的值,所以它不在X轴上移动,使用它 -
final TranslateAnimation translate = new TranslateAnimation(
Animation.ABSOLUTE,0, Animation.ABSOLUTE,
x, Animation.ABSOLUTE,y,
Animation.ABSOLUTE,1000);//How far it goes