2
我有一张图像,例如下面示出的图像: Animate(缩放和翻译)Android画布视图的一部分图像
该图像有两个部分尺寸宽度的第1部分W的宽度和高度大号和第2部分(较小的部分)瓦特和高度ħ(呼叫第一部分作为来源和第2部分作为目的地)。设第1个矩形的坐标为(从左上角开始测量):top:100 left:10 right:200 bottom:300第2个矩形的坐标为(从左上角开始测量):top 50 left:500底部:100右:700
我想动画从源到目的地,使图像翻译和放大从源到目的地。
所以我的第一个画面看起来像:
和我的第二个图像看起来像:
如何在这两者之间吐温? 我的代码(不包括动画)看起来像如下:
public class SuperGame extends View implements OnGestureListener
{
int sreenHeight, screenWidth;
int drawCount = 0;
Bitmap bg;
public SuperGame(Context context, Bitmap bmp)
{
this.screenWidth = getContext().getResources().getDisplayMetrics().widthPixels;
this.screenHeight = getContext().getResources().getDisplayMetrics().heightPixels;
bg = BitmapFactory.decodeResource(getResources(),R.drawable.bg_img);
}
@Override
/* this function triggers the image change
*/
public boolean onDown(MotionEvent e) {
invalidate(0,0,screenWidth, screenHeight);
return true;
}
@Override
public void onDraw(Canvas canvas)
{
Rect dest = new Rect(0,0,screenWidth, screenHeight);
if (count==0) //draw the first image part
{
count=1;
Rect src = new Rect(100,10,200,300);//coordinates of rectangle 1
canvas.drawBitmap(bg, src, dest, new Paint());
}
else //draw the second image part - (I'd like to show movement/ transition between these)
{
Rect src = new Rect(50,500,100,700);//coordinates of rectangle 2
count=0;
canvas.drawBitmap(bg, src, dest, new Paint());
}
}
}
如何我设置过渡动画效果(这涉及zoomin以及翻译)?
Hi @ User42,我有相同的功能来实现。我必须在屏幕上显示图像的一部分,当用户滑动屏幕时,我必须更新屏幕的其他部分。它应该有从一个位置移动到另一个位置的动画。您可以通过查看解决方案来分享您的代码吗? – Noundla