android画图学习笔记
2010-08-11 10:53:00 来源:WEB开发网tile2.draw(canvas);
Drawable tile3 = r.getDrawable(R.drawable.greenstar);
tile3.setBounds(mTileSize*2, 0, mTileSize*3, mTileSize);
tile3.draw(canvas);
canvas.drawBitmap(bitmap, 0, 0, mPaint);
Resources r = this.getContext().getResources();
Bitmap bitmap = Bitmap.createBitmap(mTileSize, mTileSize, Bitmap.Config.ARGB_8888);
Drawable tile1 = r.getDrawable(R.drawable.redstar);
tile1.setBounds(0, 0, mTileSize, mTileSize);
tile1.draw(canvas);
Drawable tile2 = r.getDrawable(R.drawable.yellowstar);
tile2.setBounds(mTileSize, 0, mTileSize*2, mTileSize);
tile2.draw(canvas);
Drawable tile3 = r.getDrawable(R.drawable.greenstar);
tile3.setBounds(mTileSize*2, 0, mTileSize*3, mTileSize);
tile3.draw(canvas);
canvas.drawBitmap(bitmap, 0, 0, mPaint);
由此可见,setBounds的前两个是图片的左上角坐标,后两个是图片右下角的坐标(并不是图片的长和宽)
canvas.drawBitmap(bitmap, 0, 0, mPaint);
改成
canvas.drawBitmap(bitmap, mTileSize, mTileSize, mPaint);
怎么没变化呢?
api解析是
写道
Draw the specified bitmap, with its top/left corner at (x,y), using the specified paint, transformed by the current matrix.
Note: if the paint contains a maskfilter that generates a mask which extends beyond the bitmap's original width/height (e.g. BlurMaskFilter), then the bitmap will be drawn as if it were in a Shader with CLAMP mode. Thus the color outside of the original width/height will be the edge color replicated.
If the bitmap and canvas have different densities, this function will take care of automatically scaling the bitmap to draw at the same density as the canvas.
Parameters
bitmap The bitmap to be drawn
left The position of the left side of the bitmap being drawn
top The position of the top side of the bitmap being drawn
paint The paint used to draw the bitmap (may be null)
--------------------------
新的Tetris不知怎么TextView不能显示在图层之上,就像Snake的状态提示text那样,在SnakeView层之上。
找了半天,才发现原来是Layout搞错了,必须要用FrameLayout才能达到这样的效果,默认的LinearLayout是不行的
更多精彩
赞助商链接