1

ビットマップ ドローアブルリピート タイルを 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 つ目が縦向きであってもかまいません。結果は両方の向きでチェックされます。

あなたの助けが必要です..

4

1 に答える 1

0

私は試してみます:

BitmapDrawable tile = (BitmapDrawable) res.getDrawable(R.drawable.background);
tile.setTileModeX(Shader.TileMode.REPEAT);

tile.setGravity(Gravity.bottom)
tile.setTileModeY(Shader.TileMode.CLAMP); 
// it replicates the edge color if the shader draws outside of its original bounds
//thus you don't even need to set a background color.

view.setBackgroundDrawable(tile);
于 2013-02-28T21:34:55.273 に答える