从View位图在Android上不显示位图、上不、View、Android

2023-09-12 09:31:38 作者:無心快語

我想创建未显示任何内容将其设置为与OpenGL在Android的纹理视图的位图。 现在的问题是,当我创建位图的我的看法布局参数有值为0的事业onLayout()函数没有被调用呢。 有没有一种方法来模拟的布局还是做一个背景布置,以获得正确的布局PARAMS? 我在想有两个视图的框架布局,后台一会被用来创建我的位图的布局将已经完成。

I am trying to create a bitmap from a View that is not displayed yet to set it as a texture with OpenGL in android. The problem is that when I create my bitmap the layout parameters of my View have 0 value cause the onLayout() function has not been called yet. Is there a way to "simulate" a layout or do a "background layout" to get the right layout params ? I was thinking about a Frame layout having two views, the background one would be used to create my bitmap as the layout would have been done.

感谢。

推荐答案

您确实需要绘制成位图前布局的视图。简单地调用myView.measure(...),那么myView.layout(0,0,myView.getMeasuredWidth(),myView.getMeasuredHeigh())。我已经张贴在如何做到这一点在以下presentations的一个例子:http://www.curious-creature.org/2010/12/02/android-graphics-animations-and-tips-tricks/

You indeed need to layout your View before drawing it into a Bitmap. Simply call myView.measure(...) then myView.layout(0, 0, myView.getMeasuredWidth(), myView.getMeasuredHeigh()). I have posted an example on how to do this in one of the following presentations: http://www.curious-creature.org/2010/12/02/android-graphics-animations-and-tips-tricks/