所以我正在进行一些旋转并在imageview上进行翻译。据我所知,在完成这些任务之后,imageview并不是真正处于一个新的位置,你必须在动画完成后将其移动到那里。所以我试图移动的imageview被称为令牌,它被设置在原始位置,token.getLocationOnScreen( tokenPos );
有它的起始位置。移动或翻译后,我致电resetToken
来处理移动或轮换。这似乎可以在一半的时间内完成预期的结果...不确定我做错了什么,但它与我面对的方式不一致。
public void resetToken() {
//Decode Image using Bitmap factory.
Bitmap bMap = Bitmap.createBitmap(token.getDrawingCache());
Matrix matrix = new Matrix();
matrix.postRotate(0);
//move the token to the spot it needs to be in
//after an animation the token is not really
//in the new spot
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(token.getWidth(), token.getHeight());
lp.setMargins(tokenPos[0], tokenPos[1], 0, 0);
//Create bitmap with new values.
Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0, token.getWidth(), token.getHeight(), matrix, true);
token.setImageBitmap(bMapRotate);
token.setLayoutParams(lp);
//put rotated image in ImageView.
moveCounter = moveCounter + 1;
}
答案 0 :(得分:1)
我能够这样做。
public void resetToken() {
Bitmap bmpOriginal = BitmapFactory.decodeResource(this.getResources(), R.drawable.robo);
Bitmap bmResult = Bitmap.createBitmap(bmpOriginal.getWidth(), bmpOriginal.getHeight(), Bitmap.Config.ARGB_8888);
Canvas tempCanvas = new Canvas(bmResult);
tempCanvas.rotate(currentMapDirection, token.getWidth(), token.getHeight());
tempCanvas.drawBitmap(bmpOriginal, 0, 0, null);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(token.getWidth(), token.getHeight());
lp.setMargins(tokenPos[0], tokenPos[1], 0, 0);
token.setLayoutParams(lp);
token.setImageBitmap(bmResult);
}