在SurfaceView- Android旁边的AnimationDrawable到framelayout

时间:2014-10-02 20:47:56

标签: android animation viewanimator

Hello all, 在我的应用程序中,当我触摸屏幕时,我可以制作一个角色(如卡通人物......)来制作动画吗?

  • 我在屏幕上有另一个位图(静态非动画)。
  • 我在所有动画位置都拥有所有这个角色(10)位图(如卡通片)

这是代码..(我需要为每个触摸动画)

`

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 个答案:

答案 0 :(得分: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;



  }