带有ImageView的Android动画

带有ImageView的Android动画,android,android-layout,animation,android-animation,android-2.2-froyo,Android,Android Layout,Animation,Android Animation,Android 2.2 Froyo,我有一个相框,应该是动画与图片在它。我将使用imageView,其中我的背景将是帧,我的图片将是前景图像。我必须以一种方式来展示它,一个相框从屏幕的顶部下降到中间,并在其顶部连接一条丝带。将其放置到中心后,只有具有图像的帧进行toFro运动,而功能区保持刚性且不移动。我该如何制作这样的动画 谢谢你需要把它画得像卡通一样。尝试先将其拍摄下来以获得所需的运动,然后创建一个PNG序列(使用Adobe After Effects),将所需的帧作为参考,然后在Illustrator或Photoshop中重

我有一个相框,应该是动画与图片在它。我将使用imageView,其中我的背景将是帧,我的图片将是前景图像。我必须以一种方式来展示它,一个相框从屏幕的顶部下降到中间,并在其顶部连接一条丝带。将其放置到中心后,只有具有图像的帧进行toFro运动,而功能区保持刚性且不移动。我该如何制作这样的动画


谢谢

你需要把它画得像卡通一样。尝试先将其拍摄下来以获得所需的运动,然后创建一个PNG序列(使用Adobe After Effects),将所需的帧作为参考,然后在Illustrator或Photoshop中重新绘制


然后使用animation.draw创建动画,只要没有太多的帧,就可以显示帧。

在活动类中声明这些变量

private ImageView myFrameAnimation;
private int iFrameCount;
private ImageView myPhotoLayer;
使用onStart或按钮单击事件启动动画

@Override
protected void onStart() {
    super.onStart();
    Thread thr1 = new Thread(r1);
    thr1.start();
}
Runnable r1 = new Runnable() {
    public void run() {
    while (iFrameCount< 747) {

        runOnUiThread(new Runnable() {
            public void run() {
                iFrameCount++;
                switch (iFrameCount) {
                    //you can use a separate procedure here to move the ImageView with your picture in time with your animation
                    //the x,y cordinates ‎l depend on your screen/View size measured from top left corner. 
                case 310: animate_object(330,215,310,215,1);
                case 315: animate_object(150,380,150,420,80);
                case 320: animate_object(80,150,80,120,100);
                }

                   //store your animation images in the drawables folder with the name like img1.png, img2.png etc.     
                String image="img" + iFrameCount;
                resID = getResources().getIdentifier(image, "drawable",  getPackageName()); 
                if (resID != 0){

                    //Use these to time how long it takes to update the imageview/ Set your thread.sleep to around this time.
                    //startTime = System.currentTimeMillis();                           
                 myFrameAnimation.setImageResource(resID);
                    //endTime = System.currentTimeMillis();
                    //Log.d("Frame: " +iFrameCount + " setBackground took: " + (endTime - startTime) + " milliseconds");

                } else {
                           //we can skip frames if they are duplicates of the frame before to save space and memory and increase speed
                     //Log.d(TAG, "File skipped: " + iFrameCount);
                }
             }
           });
        try {
           Thread.sleep(43); //43 is milliseconds to give around 23 frames per second speed will depend on your image size that you are animating.
        } catch (InterruptedException iex) {}
      }           
      //Log.d(TAG, "Finished all frames");
      finish();
   }
};
然后创建一个新线程来制作动画

@Override
protected void onStart() {
    super.onStart();
    Thread thr1 = new Thread(r1);
    thr1.start();
}
Runnable r1 = new Runnable() {
    public void run() {
    while (iFrameCount< 747) {

        runOnUiThread(new Runnable() {
            public void run() {
                iFrameCount++;
                switch (iFrameCount) {
                    //you can use a separate procedure here to move the ImageView with your picture in time with your animation
                    //the x,y cordinates ‎l depend on your screen/View size measured from top left corner. 
                case 310: animate_object(330,215,310,215,1);
                case 315: animate_object(150,380,150,420,80);
                case 320: animate_object(80,150,80,120,100);
                }

                   //store your animation images in the drawables folder with the name like img1.png, img2.png etc.     
                String image="img" + iFrameCount;
                resID = getResources().getIdentifier(image, "drawable",  getPackageName()); 
                if (resID != 0){

                    //Use these to time how long it takes to update the imageview/ Set your thread.sleep to around this time.
                    //startTime = System.currentTimeMillis();                           
                 myFrameAnimation.setImageResource(resID);
                    //endTime = System.currentTimeMillis();
                    //Log.d("Frame: " +iFrameCount + " setBackground took: " + (endTime - startTime) + " milliseconds");

                } else {
                           //we can skip frames if they are duplicates of the frame before to save space and memory and increase speed
                     //Log.d(TAG, "File skipped: " + iFrameCount);
                }
             }
           });
        try {
           Thread.sleep(43); //43 is milliseconds to give around 23 frames per second speed will depend on your image size that you are animating.
        } catch (InterruptedException iex) {}
      }           
      //Log.d(TAG, "Finished all frames");
      finish();
   }
};

谢谢,但我需要在运行时集成一张图片,即从画廊或相机拍摄照片,然后将其添加到动画中。所以这可能对我不起作用。嗨,小子,你想选择还是拍照,然后让它出现在屏幕上的相框中?如果是这种情况,您将创建我上面提到的动画。先把它拍成电影,以获得运动效果。然后在动画程序中绘制它(如Flash或After Effects)。创建帧的PNG图像序列(如卡通)。使大小尽可能小(不是全屏)。然后…要么使用animation.drawable(如果它足够小),要么一次循环切换一个PNG(我就是这么做的),然后让您的图片在图片帧动画层顶部的不同Imageview中设置动画,然后按顺序逐帧移动顶部Imageview,使其在下降和摆动时保持在帧内。我编辑了一些我使用的现有代码,希望所有的括号都放在正确的地方。