Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
553 views
in Technique[技术] by (71.8m points)

layout - Bitmap from View not displayed on Android

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.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.getMeasuredHeight());

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...