我是Android的动画初学者。 我想设置动画像Pendulum(从左到右摆动)到我的Activity中的图像。
到目前为止我所做的是:Animation anim = new RotateAnimation(0, 30, 0, 0);
anim.setRepeatMode(Animation.REVERSE);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.setDuration(1500);
anim.setFillAfter(true);
但它根本不起作用...... 任何人都可以建议我怎么做动画?
谢谢....
答案 0 :(得分:10)
我遇到了完全相同的问题,最终得到了一个仅限xml的解决方案:http://blog.sqisland.com/2012/01/android-pendulum-animation.html
答案 1 :(得分: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();
}
}
}
在这个例子中,我从服务器附加图像,但你也可以设置它可绘制和显示动画
答案 2 :(得分:0)
如果我是你,并且做了如此复杂的动画,我会尝试使用canvas的简单API来绘制和动画对象。请查看lunarLandar示例。
非常简单,如果您控制对象的实际位置,只需创建一个调整X&amp;对象的Y.
<强>须藤:强>
-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.