【发布时间】:2017-08-07 19:23:45
【问题描述】:
我有一个问题。如何为移动视图设置动画?我想在移动时生成一个字母并为其设置动画(旋转和缩放)。如果我只启动动画,它可以按我的意愿工作,或者如果我只运行 move 方法,它也可以工作,但不能一起工作。以下是代码的屏幕: 主活动的 run 方法为每个视图调用 Move 方法
public Letter (FrameLayout container, Random rnd, Animation animation){
view = new TextView(container.getContext());
letter = letters[rnd.nextInt(letters.length)];
view.setText(letter);
view.setTextColor(Color.rgb(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256)));
view.setGravity(Gravity.CENTER);
container.addView(view);
x = container.getWidth();
y = container.getHeight();
vx = 2 * rnd.nextFloat() * (rnd.nextBoolean()?1:-1);
vy = 2 * rnd.nextFloat() * (rnd.nextBoolean()?1:-1);
view.startAnimation(animation);
move();
}
public void move() {
x+= vx;
y+=vy;
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams();
params.leftMargin = Math.round(x);
params.topMargin = Math.round(y);
params.gravity = Gravity.LEFT+Gravity.TOP;
view.setLayoutParams(params);
}
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!--<scale
android:fromXScale="1"
android:fromYScale="1"
android:toXScale="3"
android:toYScale="3"
android:pivotY="50%"
android:pivotX="50%"
android:duration="10000"
>
</scale>
-->
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration = "3000"
android:repeatCount="infinite"
>
</rotate>
</set>
【问题讨论】:
-
请把代码作为文本,而不是图片)
-
完成...........
标签: android android-studio animation textview move