2014-10-02 53 views
0

Hello all, 在我的應用程序中,當我觸摸屏幕時,我可以製作一個角色(如卡通人物...)來動畫嗎?AnimationDrawable在SurfaceView旁邊的framelayout中 - Android

  • 我在屏幕上有另一個位圖(靜態不動畫)。
  • 我都這個人物(10)在所有的動畫位置(像動畫片)

這是代碼的位圖。(我需要製作動畫FOR每個觸摸)

`

import java.util.ArrayList; 
import java.util.List; 
import android.app.Activity; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.graphics.drawable.AnimationDrawable; 
import android.os.Bundle; 
import android.view.MotionEvent; 
import android.view.View; 
import android.view.Window; 
import android.widget.FrameLayout; 
import android.widget.FrameLayout.LayoutParams; 
import android.widget.ImageView; 

public class Show extends Activity 
{ 
private Bitmap imageOne; 
private Bitmap imageTwo; 
private Bitmap imageThree; 
private List<Bitmap> images; 
private ExplainView myView; 
private AnimationDrawable animation; 
private ImageView image;` 
@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setFlags(0x00000400, 0x00000400); 
    setContentView(R.layout.frame_layout); 

    image = new ImageView(this); 
    image.setBackgroundResource(R.drawable.tom_anim); 
    animation = (AnimationDrawable) rocketImage.getBackground(); 

    images = new ArrayList<Bitmap>(); 
    praper(); 
    myView = new ExplainView(this,images,1); <------ this is the surface view class 

    FrameLayout fl = (FrameLayout)findViewById(R.id.frameLayout); 
    fl.addView(myView); 
    fl.addView(image); 

} 
@Override 
public boolean onTouchEvent(MotionEvent event) 
{ 
    if(event.getAction() == MotionEvent.ACTION_DOWN) 
    { 
    new Runnable() { 
     @Override 
     public void run() { 
       image.setVisibility(View.VISIBLE); 
       animation.stop(); 
       animation.start(); 
     } 
     };   
    } 
     return true; 
} 
private void praper() 
{ 
    imageOne = BitmapFactory.decodeResource(getResources(), R.drawable.trans_ar_alpha_1); 
    imageTwo = BitmapFactory.decodeResource(getResources(), R.drawable.trans_ar_alpha_2); 
    imageThree = BitmapFactory.decodeResource(getResources(), R.drawable.trans_ar_alpha_3); 
    images.add(0,imageOne); 
    images.add(1, imageTwo); 
    images.add(2, imageThree); 

} 
@Override 
public void onWindowFocusChanged(boolean hasFocus) { 
    // TODO Auto-generated method stub 
    if(hasFocus) 
    { 
      animation.start(); 
    } 
    else 
    { 
      animation.stop(); 
    } 
} 

}`

回答

1
當然

,你可以簡單地通過使用

@Override 
    public boolean onTouch(View arg0, MotionEvent arg1) { 
// TODO Auto-generated method stub 
x = arg1.getX(); 
y = arg1.getY(); 
switch(arg1.getAction()) 
{ 
case MotionEvent.ACTION_DOWN: 
    sx=arg1.getX(); 
    sy = arg1.getY(); 
    break; 
case MotionEvent.ACTION_UP: 
    fx=arg1.getX(); 
    fy = arg1.getY(); 
    break; 



    }