1
我有一個問題。我怎樣才能動畫一個移動視圖?我想生成一個字母,並在移動時對其進行動畫處理(旋轉和縮放)。如果我只是開始動畫就可以按照我的想法工作,或者如果我只運行移動方法,它也可以起作用,但不起作用。下面是代碼的畫面: Move方法得到由在MainActivityAndroid Studio如何動畫移動視圖?
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>
請包括代碼作爲文本,而不是圖片) –
完成........... – Domooo93