【发布时间】:2012-01-30 09:52:35
【问题描述】:
我必须得到一个布局的位图(比如第二个屏幕)之前(可以说没有)将它带到前台屏幕。我提到了this 帖子。我在夸大视图的地方做错了。 注意:
1. Must not show the inflated screen (second screen)
2. Must not attach it to the parent view
我的代码 sn-p 在这里:
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
我的预览总是空白。谢谢。
【问题讨论】:
-
你可以要求我澄清:) 我认为我在膨胀视图方面犯了错误......
-
你试过调试宽度和高度吗?如果我没记错的话,以这种方式检索时,这两个变量等于 0...
-
@Sephy 你是对的实际上我打印了位图的高度和宽度。第二视图的高度和宽度是 0,0。但是如果我在膨胀视图中提到视图组它会出现在屏幕中......我怎样才能获得符合我要求的位图......
标签: android bitmap layout-inflater