2

レイアウトのビットマップを取得する必要があります (たとえば、2 番目の画面)前に(なくてもかまいません)、それを前景画面に移動します。この投稿を参考にしました。ビューを膨らませる際にどこかで間違いを犯しています。ノート:

1. Must not show the inflated screen (second screen)
2. Must not attach it to the parent view

私のコードスニペットはここにあります:

private Bitmap renderNextScreen() {
    
    // Getting width, height device
    Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    
    Log.i(TAG, "Width- " + width+" Height - "+height);

    // Create a mutable bitmap
    Bitmap secondScreen = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    
    // Created a canvas using the bitmap
    Canvas c = new Canvas(secondScreen);
    
    // Inflated the second screen
    LayoutInflater inflater = LayoutInflater.from(this);
    View secondView = inflater.inflate(R.layout.secondscreen, null);
    
    Log.i(TAG, "secondView.Height- "+secondView.getHeight()+" , secondView.Width " + secondView.getWidth());
    // Drawn the inflated view to canvas
    secondView.draw(c);
    
    preview.setImageBitmap(secondPage); // preview is the Imageview inside first screen
    return secondScreen;
}

高さ、幅の私のログ:

01-28 02:12:35.926: I/FirstActivity(21831): Width- 480 Height - 800
01-28 02:30:08.287: I/FirstActivity(22207): secondView.Height- 0 , secondView.Width 0

私のプレビューは常に空白でした。ありがとうございました。

4

1 に答える 1

2

変更すると思います:

View secondView = inflater.inflate(R.layout.secondscreen, null);

に:

View secondView = inflater.inflate(R.layout.secondscreen, null, false);

次に、膨張したビューのレイアウト パラメータを次のように宣言する必要があります。

secondView.setLayoutParams(new LayoutParams(displaymetrics.widthPixels, 
displaymetrics.heightPixels/3));

Displaymetrics は、電話画面のサイズを保持する変数でした。

次に、そのビューを bmp に変換できるはずです。

于 2012-07-27T20:58:32.230 に答える