Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android中,像曲线一样进行翻译_Android_Animation - Fatal编程技术网

在android中,像曲线一样进行翻译

在android中,像曲线一样进行翻译,android,animation,Android,Animation,如何创建动画以将图像像曲线一样从上到下移动?这里我用了TranslateAnimation, 但它会根据x,y坐标从上到下移动图像。但是,我想像曲线一样移动图像。 但在我的代码中,它像一条线一样移动 public class ImageMoveActivity extends Activity { /** Called when the activity is first created. */ TranslateAnimation transform; TextView

如何创建动画以将图像像曲线一样从上到下移动?这里我用了TranslateAnimation, 但它会根据x,y坐标从上到下移动图像。但是,我想像曲线一样移动图像。 但在我的代码中,它像一条线一样移动

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);
            }

        });


    }
}

有人能帮我吗?

翻译动画可以将视图沿直线从一点移动到另一点。据我所知,你不能给它任何其他途径。尝试为此使用自定义视图和画布,在绘制视图并使其无效时可以传递x和y坐标。扩展视图类时,需要重写以下方法。这里的ChangeCoordination方法可以更改曲线中的x、y坐标

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

可以在曲线上创建一系列从一个点到另一个点的平移动画,并将动画应用于视图

就像我们有一个要设置动画的imageView,a1和a2是要应用的动画:

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

  imgView.clearAnimation();
    imgView.startAnimation(a2);