Android 如何使图像变小而不是其原始大小?
我正在android上开发一个动画应用程序。 我在应用中有一个大的形象。 图像应从屏幕中央开始。在初始阶段,图像大小将更大。移动到屏幕左侧时,其大小应减小(即应进行缩放)。图像不应回到其原始位置。动画结束后,应将其放置在屏幕左侧 谁能帮忙吗。Android 如何使图像变小而不是其原始大小?,android,android-layout,Android,Android Layout,我正在android上开发一个动画应用程序。 我在应用中有一个大的形象。 图像应从屏幕中央开始。在初始阶段,图像大小将更大。移动到屏幕左侧时,其大小应减小(即应进行缩放)。图像不应回到其原始位置。动画结束后,应将其放置在屏幕左侧 谁能帮忙吗。 谢谢。此函数用于调整位图大小 public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) { int width = bm.getWidth(); int
谢谢。此函数用于调整位图大小
public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
matrix.postRotate(90);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height,
matrix, false);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
resizedBitmap.compress(Bitmap.CompressFormat.PNG, 70, bytes);
return resizedBitmap;
}
如果我理解正确,你想显示一个图像,然后设置动画,使它看起来像是缩小了,给人一种进入背景的感觉 您需要使用ScaleAnimation 有关android动画的良好教程,请访问:
你的意思是你想从中心调整它的大小?我想使它比原来的大小小一些,而且它应该在调整大小时向后移动。你向后移动是什么意思?它应该被隐藏?它应该从原来的位置向后移动,而你可以通过矩阵变换图像来移动它的位置。汉克斯或莱米,它起作用了。图像在屏幕上缩放,但现在我想在特定点停止图像缩放,我该怎么做?