ビットマップ ドローアブルリピート タイルを xに作成しようとしています。このドローアブル ビューを下に揃えて(空き領域を色で塗りつぶす)、ドローアブルが y に収まらないようにします。
そして、私は必ず目標を達成しなければなりません。
ソースの背景画像:
大きな画面でこの画像の上の空きスペースを塗りつぶす色: #FF5cc8f2
最初のバリアントは次のとおりです。
BitmapDrawable tile = (BitmapDrawable) res
.getDrawable(R.drawable.background);
tile.setTileModeX(Shader.TileMode.REPEAT);
view.setBackgroundColor(res.getColor(R.color.background));
view.setBackgroundDrawable(tile);
結果:
ご覧のとおり、雲の下に不要な空白があります。
2 番目のバリアント:
BitmapDrawable bd = (BitmapDrawable) res.getDrawable(R.drawable.background);
WindowManager wm = (WindowManager) AvApplication.getInstance().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int width;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
width = display.getWidth();
} else {
Point size = new Point();
display.getSize(size);
width = size.x;
}
int intrinsicHeight = bd.getIntrinsicHeight();
Rect bounds = new Rect(0,0,width,intrinsicHeight);
bd.setTileModeX(TileMode.REPEAT);
bd.setBounds(bounds);
Bitmap bitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), bd.getBitmap().getConfig());
Canvas canvas = new Canvas(bitmap);
bd.draw(canvas);
BitmapDrawable bitmapDrawable = new BitmapDrawable(res, bitmap);
view.setBackgroundDrawable(bitmapDrawable);
結果:
現在、画像は下にありますが、引き伸ばされています
1 つのスクリーンショットが横向きで、2 つ目が縦向きであってもかまいません。結果は両方の向きでチェックされます。
あなたの助けが必要です..