如何在安卓中像钟摆一样摇摆图片?

4

我是一个Android动画的初学者。 我想在我的Activity中对图片设置像钟摆一样(从左到右摆动)的动画。

目前为止我做的是:

Animation anim = new RotateAnimation(0, 30, 0, 0);
anim.setRepeatMode(Animation.REVERSE);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.setDuration(1500);
anim.setFillAfter(true);

但是它根本不起作用... 有人能建议我如何制作动画吗?

谢谢....

3个回答

10

0

这将会帮助你 ::

      AnimationDrawable Tranninganimation5;

       Tranninganimation1 = new AnimationDrawable();
            new playninzi().execute();
            animation.setOneShot(false);
            Tranninganimation1.setOneShot(false);

private class playninzi extends AsyncTask<Void, Void, Void> {
        private final ProgressDialog dialog = new ProgressDialog(
                Signs_main_page.this);

        protected void onPreExecute() {
            this.dialog.setMessage("Please Wait...");
            this.dialog.show();

            try {
                for (int i = 1; i < 25; i++) {
                    Bitmap bitmap = BitmapFactory
                            .decodeStream((InputStream) new URL(
                                    "http://203.a44.115.55/MRESC/images/test/girl2/"
                                            + "girl-1000" + i + ".png")
                                    .getContent());
                    Drawable frame = new BitmapDrawable(bitmap);
                    animation.addFrame(frame, 50);
                }
            } catch (Exception e) {

            }
        @Override
        protected Void doInBackground(Void... arg0) {
            return null;
        }
        protected void onPostExecute(final Void unused) {
            if (this.dialog.isShowing()) {
                this.dialog.dismiss();
            }
        }
    }

在这个例子中,我已经从服务器附加了图像,但您也可以将其设置为可绘制并显示动画。

0

如果我是你,而且正在做这样复杂的动画,我会尝试查看canvas的简单API来绘制和动画化对象。可以参考lunarLandar的示例。

如果您控制对象的实际放置位置,那么很容易创建一个公式来调整对象的X和Y坐标。

Sudo:

-If object is going right, and is left of center, decrease it's Y value.
-If object is going right, and is right of center, increase it's Y value.
-If the object is going left, and is right of center, decrease it's Y value.
-If the object is going left, and is left of center, increase it's Y value.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接