2011-09-07 26 views
3

我是Android的動畫初學者。 我想設置像Pendulum(Swing從左到右)的動畫來在我的Activity中成像。如何在android中擺動像鐘擺一樣的圖像?

是我迄今所做的是:

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

不過,這並不在所有的工作...... 任何人可以建議我怎麼做動畫?

謝謝....

回答

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

如果我是你,並且做了如此複雜的動畫,我會嘗試查看簡單的API canvas來繪製和製作對象的動畫。以lunarLandar爲例。

會很簡單,如果您控制對象的實際位置,只需創建一個調整對象的X的公式即可。

須藤:

-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.