我有一个相框,应该用其中的图片进行动画处理。我将使用一个 imageView,其中我的背景将是框架,而我的图片将是前景图像。我必须以一种相框从顶部落入屏幕中间的方式来展示它,并在其顶部附有一条丝带。将其放入中心后,只有带有图像的框架进行 toFro 运动,而色带保持刚性并且不移动。我应该如何制作这样的动画?
谢谢
我有一个相框,应该用其中的图片进行动画处理。我将使用一个 imageView,其中我的背景将是框架,而我的图片将是前景图像。我必须以一种相框从顶部落入屏幕中间的方式来展示它,并在其顶部附有一条丝带。将其放入中心后,只有带有图像的框架进行 toFro 运动,而色带保持刚性并且不移动。我应该如何制作这样的动画?
谢谢
在您的 Activity 类中声明这些变量
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();
}
};
最后有一个程序来动画照片和你的相框
public void animate_object(int startx, int starty, int endx, int endy, int duration)
{
//photoLayer is the Id of your imageView holding the photo. You would need to have previously loaded your photo into the imageview using
//something like this myPhotoLayer.setImageResource(resID); before the animation is started.
myPhotoLayer = (ImageView) findViewById(R.id.photoLayer);
TranslateAnimation move = new TranslateAnimation(startx, endx, starty, endy);
move.setDuration(duration);
move.setFillAfter(true);
myPhotoLayer.startAnimation(move);
}
你需要像卡通一样画它。首先尝试拍摄视频以获得您需要的运动,然后创建一个 PNG 序列(使用 Adobe After Effects),将您想要的帧作为指导,然后在 Illustrator 或 Photoshop 中重新绘制它们。
然后使用 animation.drawable 创建一个动画来显示帧,只要它没有太多帧。