ロジック的には下のような感じ、while分の中で描画したい大きさに達するまで位置を変えて繰り返し描くだけです。
//描画領域Rect
Rect r = new Rect(left, top, left + width, top + height);
//画像幅取得
int imgWidth = background.getWidth();
//画像高さ取得
int imgHeight = background.getHeight();
switch (layout) {
case BACK_FIT : //領域全体
canvas.drawBitmap(background, imgRect, new Rect(r.left, r.top, r.width(), r.height()), paint);
break;
case BACK_VREPEAT : //縦の繰り返し
int sh = 0;
while (sh < height) {
canvas.drawBitmap(background, imgRect, new Rect(r.left, r.top + sh, r.width(), imgHeight), paint);
sh += imgHeight; //画像の高さ分足す
}
break;
case BACK_HREPEAT : //横の繰り返し
int sw = 0;
while (sw < width) {
canvas.drawBitmap(background, imgRect, new Rect(r.left + sw, r.top, imgWidth, r.height()), paint);
sw += imgWidth; //画像の幅分足す
}
break;
}
最後の描画で描画領域を考慮していないのではみ出すことがありますが、それで困る場合は先日書いたSurfaceViewで描画範囲を限定するを利用するとよいでしょう。
0 件のコメント:
コメントを投稿