Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.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_Path_Coordinates_Translate Animation - Fatal编程技术网

如何在android中为图像设置动画,使其遵循由多个坐标组成的路径?

如何在android中为图像设置动画,使其遵循由多个坐标组成的路径?,android,animation,path,coordinates,translate-animation,Android,Animation,Path,Coordinates,Translate Animation,我发现图像在两点之间的移动可以通过以下简单代码实现: ImageView image_to_move = (ImageView) findViewById(R.id.image_to_move); TranslateAnimation animation = new TranslateAnimation(50, 100, 50, 100); animation.setDuration(5000); image_to_move.startAnimatio

我发现图像在两点之间的移动可以通过以下简单代码实现:

    ImageView image_to_move = (ImageView) findViewById(R.id.image_to_move); 
    TranslateAnimation animation = new TranslateAnimation(50, 100, 50, 100);
    animation.setDuration(5000);     
    image_to_move.startAnimation(animation);
图像是最初设置在FrameLayout内位置(0,0)的ImageView,代码将其从点(50,50)移动到(100100)。 如果我必须以绝对坐标(x,y)的形式在一条由多个点组成的路径上移动它怎么办?例如,从(50,50)移动到(75,75),然后移动到(100100) 有一种方法可以将坐标数组传递给平移函数,或者我只需对每两个点迭代动画

顺便说一句,我看到如果我最初没有在(0,0)中定位图像,函数会以一种奇怪的方式移动图像,就像我给出的坐标不是绝对的。我错过什么了吗? 编辑:最后一件事发生在我将参数传递给TranslateAnimation时,类似于“n92.getX()”,其中n92是帧布局上的一个按钮,我希望动画从该位置开始。
细节:只是为了更好地理解这个问题:我正在实现一个点在地图上移动的动画,向用户展示如何从地图的一个点到另一个点。这就是为什么我必须遵循绝对坐标(可达点)(如果不遵循地图上的精确路径,就无法从一个点到达另一个点)

为此,需要计算二次贝塞尔曲线上的位置。试试这个,它可能对你有用,但我不需要它在弯曲的路径上移动。相反,我需要它在几个点之间的直线上移动:一条丑陋但实用的方形路径^^