Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓,上下动画图像_Android_Image_Animation - Fatal编程技术网

Android 安卓,上下动画图像

Android 安卓,上下动画图像,android,image,animation,Android,Image,Animation,我正在尝试动画图像开始贝娄屏幕,上升,然后下降(做银河标签应用程序)。 这两个动画分别工作,但当我尝试创建AnimationSet时,我无法让它们工作。 我甚至尝试创建2个异步任务,并在第一个异步任务的onPostExecute中调用第二个动画,但仍然不起作用 这是我的XML <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_par

我正在尝试动画图像开始贝娄屏幕,上升,然后下降(做银河标签应用程序)。 这两个动画分别工作,但当我尝试创建AnimationSet时,我无法让它们工作。 我甚至尝试创建2个异步任务,并在第一个异步任务的onPostExecute中调用第二个动画,但仍然不起作用

这是我的XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:id="@+id/rel_layout"
   >
    <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ad200"
        android:id="@+id/image"
    />
</RelativeLayout>

看起来您正在同时启动两个动画。将anim2.setStartOffset(3000)添加到第二个动画中。这将导致第二个动画在第一个动画之后3000毫秒开始

比尔, 克里斯托弗

WendiKidd

您非常接近您的解决方案。您刚刚错过了代码中的Animation.AnimationListener()

Animation anim1 = new TranslateAnimation(0, 0, 1024, 824);
anim1.setDuration(3000);
anim1.setFillAfter(true);

anim1.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                Animation anim2 = new TranslateAnimation(0, 0, 824, 1024);
                anim2.setDuration(3000);
                anim2.setFillAfter(true);
                imageView.clearAnimation();
                imageView.startAnimation(anim2);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });


imageView.startAnimation(anim1);

上面的示例将在anim1结束后启动anim2。

这是一个解决方案…请尝试下面的代码。。我多次使用这个代码。。而且效果很好..===>

    Animation zoomin =new TranslateAnimation(1, 1, 0, -50);
    zoomin.setDuration(1000);
    zoomin.setFillEnabled(true);
    zoomin.setFillAfter(true);

    Animation zoomout =  new TranslateAnimation(1, 1, -50, 0);
    zoomout.setDuration(1000);
    zoomout.setFillEnabled(true);
    zoomout.setFillAfter(true);

    imageView.startAnimation(zoomin);

    zoomin.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationEnd(Animation arg0) {
            imageView.startAnimation(zoomout);
          }
    });

    zoomout.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationEnd(Animation arg0) {

            imageView.startAnimation(zoomin);


        }
    });

我已经试过了,我还是只看到黑屏,什么也没发生。
    Animation zoomin =new TranslateAnimation(1, 1, 0, -50);
    zoomin.setDuration(1000);
    zoomin.setFillEnabled(true);
    zoomin.setFillAfter(true);

    Animation zoomout =  new TranslateAnimation(1, 1, -50, 0);
    zoomout.setDuration(1000);
    zoomout.setFillEnabled(true);
    zoomout.setFillAfter(true);

    imageView.startAnimation(zoomin);

    zoomin.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationEnd(Animation arg0) {
            imageView.startAnimation(zoomout);
          }
    });

    zoomout.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationEnd(Animation arg0) {

            imageView.startAnimation(zoomin);


        }
    });