2

我想做一个动画,一个从右到左移动的波浪。我做了一个波浪的图像,它的开始与结束重合

在此处输入图像描述

我想做一个波浪移动的动画,animationlist我需要超过 400 帧,并且应用程序的大小会变大......

我需要一种方法来将这个唯一的框架从右到左移动,有什么帮助吗?

4

3 回答 3

0

您可以创建Drawable自己的实现Animatable,并让图像从右向左移动。拥有它实际上是一件非常有用的事情。但是,您将无法从 XML 中指定它,您必须构建它并以编程方式对其进行设置。

于 2012-05-20T20:26:03.870 回答
0

首先,您必须将图像 src 的大小加倍,有 2 个波而不是一个。接下来,您必须使用图像视图的框架边界,您必须适合一个波。这就是线索。

在记下您的图像大小,尤其是宽度之后。

对于动画,使用这个:

<?xml version="1.0" encoding="utf-8"?>
<translate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0%"
    android:toXDelta="-50%"
    android:fromYDelta="0%"
    android:toYDelta="0%"
    android:duration="500"
    android:repeatCount="1000"
    android:interpolator="@android:anim/linear_interpolator"
    android:zAdjustment="top" />

例如,您可以将其命名为 res/anim/wave.xml

班级活动?):

    ...
    Animation anim = AnimationUtils.loadAnimation( this, R.anim.wave);
    anim.setRepeatMode(Animation.Infinite);
    animatedIm = (ImageView) findviewbyid(<your-id>)
    animatedIm.setAnimation(anim); 

您可能需要使用 imageview 大小,才能有连续的波浪移动

于 2012-05-21T09:30:56.530 回答
0

你甚至可以创建一个 gif 并播放这个 GIF:下面是代码:

类 MainActivity:

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(new MYGIFView(MainActivity.this));
    }

}

MYGIFView 类:

import java.io.InputStream;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Movie;
import android.view.View;

class MYGIFView extends View {

    Movie movie, movie1;
    InputStream is = null, is1 = null;
    long moviestart;

    public MYGIFView(Context context) {
        super(context);

        // Provide your own gif animation file

        is = context.getResources().openRawResource(R.drawable.animation);
        movie = Movie.decodeStream(is);

    }

    @Override
    protected void onDraw(Canvas canvas) {

        canvas.drawColor(Color.WHITE);
        super.onDraw(canvas);
        long now = android.os.SystemClock.uptimeMillis();
        System.out.println("now=" + now);
        if (moviestart == 0) { // first time
            moviestart = now;

        }
        System.out.println("\tmoviestart=" + moviestart);
        int relTime = (int) ((now - moviestart) % movie.duration());
        System.out.println("time=" + relTime + "\treltime=" + movie.duration());
        movie.setTime(relTime);
        movie.draw(canvas, this.getWidth() / 2 - 20, this.getHeight() / 2 - 40);
        this.invalidate();
    }
}

可绘制文件夹内将是您的 GIF 图像。

于 2012-05-21T09:56:41.963 回答