Never mind. I managed to solve it myself. Hopefully, this is also the right way of doing it. :)
I need to manually call View.measure() and View.layout() on the inflated view every time I change something. The tricky part is that the measure() method needs values taken from View.MeasureSpec.makeMeasureSpec(), like this; int measuredWidth = View.MeasureSpec.makeMeasureSpec(bitmapWidth, View.MeasureSpec.EXACTLY); int measuredHeight = View.MeasureSpec.makeMeasureSpec(bitmapHeight, View.MeasureSpec.EXACTLY); offscreenView.measure(measuredWidth, measuredHeight); offscreenView.layout(0, 0, offscreenView.getMeasuredWidth(), offscreenView.getMeasuredHeight()); Also, I must use a Canvas backed by a Bitmap when drawing. Using the drawing cache doesn't seem to work well. Please correct me if I'm doing something wrong here. Hope this can help the rest of you otherwise. :) // Erik On May 26, 10:44 am, Erik H <[email protected]> wrote: > Hi, > > I'm having a small problem with drawing a View offscreen to a Bitmap. > > The View is created using LayoutInflater.inflate(int resource, > ViewGroup root) with null passed to the root parameter. The View has a > fixed size (200x180 pixels). I can create a Bitmap for this View > either by using the method View.getDrawingCache() or by calling > View.draw(Canvas canvas) using a Canvas that in turn has a backing > Bitmap. > > This works fine if the View doesn't change after the inflate. However, > if I have a TextView inside my View that I will update, the size of > the TextView is never updated regardless of what method I call on the > View (requestLayout(), forceLayout() invalidate() etc.). If I display > the View on screen directly, everything works fine (sizes are updated > as needed, etc.). > > What is the correct way of drawing Views off screen and being able to > update their layout when needed? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

