2012-02-29 11 views
0

イメージをカーブのように上から下に移動するアニメーションを作成するにはどうすればよいですか?ここで私はTranslateAnimationをこれに使用しました。 しかし、上から下に画像を移動するのはx、yの座標に依存します。しかし、私はイメージをカーブのように動かしたい。 しかし、私のコードでは、行のように動きます。TranslateAnimationはアンドロイドの曲線のようです

public class ImageMoveActivity extends Activity { 
    /** Called when the activity is first created. */ 
    TranslateAnimation transform; 
    TextView tv; 
    ImageView im1,im2,im3; 

    @Override 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     transform = new TranslateAnimation(0, 150, 0, 300); 
     //transform = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 1, Animation.RELATIVE_TO_PARENT, 20, Animation.RELATIVE_TO_PARENT, 50, Animation.RELATIVE_TO_PARENT, 0); 
     //im1 = (ImageView)findViewById(R.id.imageView1); 
     im1 = (ImageView)findViewById(R.id.imageView1); 
     im2 = (ImageView)findViewById(R.id.imageView2); 
     im3 = (ImageView)findViewById(R.id.imageView3); 
     tv = (TextView)findViewById(R.id.Textview); 


     Bitmap bitmap = BitmapFactory.decodeResource(this 
       .getResources(), R.drawable.xxl); 
     /* set other image top of the first icon */ 
     Bitmap bitmapStar = BitmapFactory.decodeResource(this 
       .getResources(), R.drawable.icon); 

     Bitmap bmOverlay = Bitmap.createBitmap(bitmap.getWidth(), 
       bitmap.getHeight(), Config.ARGB_8888); 
//  Bitmap bmOverlay1 = Bitmap.createBitmap(bitmapStar.getWidth(), 
//    bitmapStar.getHeight(), Config.ARGB_8888); 
     Canvas canvas = new Canvas(bmOverlay); 
     //Canvas canvas1 = new Canvas(bmOverlay1); 
     canvas.drawARGB(0x00, 0, 0, 0); 
     canvas.drawBitmap(bitmap, 0, 0, null); 
     //canvas1.drawARGB(0x00, 0, 0, 0); 
     canvas.drawBitmap(bitmapStar, 0, 0, null); 

     BitmapDrawable dr = new BitmapDrawable(bmOverlay); 
     //BitmapDrawable dr1 = new BitmapDrawable(bmOverlay1); 
     dr.setBounds(10, 30, 10, 30); 
     //dr1.setBounds(10, 30, 10, 30); 

     im1.setImageDrawable(dr); 
     //im3.setImageDrawable(dr1); 

//im1.setImageDrawable(R.drawable.xxl); 
     im1.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       start(); 
       hide(); 
      } 
      private void start() { 
       // TODO Auto-generated method stub 
       im1.startAnimation(transform); 
       transform.setDuration(1000); 
       //transform.setFillAfter(true); 
      } 
      private void hide() { 
       // TODO Auto-generated method stub 
       im1.setVisibility(View.GONE); 
      } 

     }); 


    } 
} 

いずれにしても私を助けますか?

答えて

0

TranslateAnimationは、1つの点から別の点にビューを直線で移動できます。あなたが知っている限り、あなたはそれに他の道を与えることはできません。このためにカスタムビューとキャンバスを使用してみてください。このビューでは、ビューを描画して無効にするときにx座標とy座標を渡すことができます。 Viewクラスを拡張している間は、次のメソッドをオーバーライドする必要があります。ここのchangeCoordinate()メソッドは、曲線のx、y座標を変更できます。

public void onDraw(Canvas canvas){ 
    canvas.drawBitmap(bitmap,x,y,null); 
    changeCoordinate(); 
    invalidate() 
} 
0

あなたは、曲線上のある地点から別の地点への変換アニメーションのシリーズを作成し、ビューにアニメーションを適用することができます。

私たちがアニメ化されるImageViewの、そしてA1、A2とを持っている場合に適用されるアニメーションしているように:

imgView.clearAnimation(); 
    imgView.startAnimation(a1); 

    imgView.clearAnimation(); 
    imgView.startAnimation(a2); 
関連する問題