【发布时间】:2014-12-02 09:53:23
【问题描述】:
在我的应用程序中,我有一个长长的绿草位图。我必须修复位图,使其底部不会移动,它应该放在屏幕的左下角。所以我必须修复它枢轴在位图的底部中心。之后我应该将位图(如随风移动的草)向左移动一些像素,向右移动一些像素距离。但是位图不应该移动它的枢轴位置。我我无法固定枢轴位置并实现草的移动。我发布了我已经完成的代码。请帮我解决这个问题。
private float direction = 1;
private float mangle = 0;
Bitmap green_1 = BitmapFactory.decodeResource(getResources(),
R.drawable.green_1);
private void drawPaper(Canvas canvas){
Paint paint=new Paint();
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
if (mangle >= 3) {
direction=-0.2f;
} else if (mangle<=-3) {
direction=0.2f;
}
mangle = mangle + direction;
Matrix matrix = new Matrix();
matrix.postTranslate(0,heightOfCanvas-green_1.getHeight());
matrix.postTranslate(0, mangle);
canvas.drawBitmap(green_1, matrix, paint);
}
提前致谢。
【问题讨论】: