gpt4 book ai didi

android - 创建屏幕外布局的位图

转载 作者:行者123 更新时间:2023-11-29 00:41:28 25 4
gpt4 key购买 nike

我必须得到布局的位图(比如第二个屏幕)之前(可以说没有)将它带到前台屏幕。我提到了this邮政。我在夸大 View 的某个地方犯了错误。注意:

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

我的代码 fragment 在这里:

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

我的预览总是空白的。谢谢。

最佳答案

我认为改变:

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

到:

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

然后您需要为膨胀 View 声明布局参数,例如:

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

Displaymetrics 是一个保存手机屏幕尺寸的变量。

然后您应该能够将该 View 转换为 bmp。

关于android - 创建屏幕外布局的位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9062015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com