I want to convert a RelativeLaout view into a Bitmap. I've tried
another answers and different options without success. My XML View is
kind of:
----RelativeLayout
-------ImageView
-------TextView
Every ones have wrap_content measures.
As i need several bitmaps of the view, im inflating it this way:
LayoutInflater inflater =
(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.localviewlayout, null);
ImageView img = (ImageView) v.findViewById(R.id.imgPlace);
img.setImageBitmap(MyDynamicBitmap);
TextView txt1 = (TextView)v.findViewById(R.id.text1);
txt1.setText(MyDynamicText);
return v;
Then, i read i need to use measure() and layout() functions, so i did
it, but i found some problems:
v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0,
MeasureSpec.UNSPECIFIED));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap( v.getWidth(), v.getHeight(),
Bitmap.Config.ARGB_8888);
v.draw(new Canvas(b));
Paint p = new Paint();
myMainCanvas.drawBitmap(b, myPointX, myPointY, p);
When the measure() function is called i get a nullpointerException on
RelativeLayout.onMeasure().I also have tried with MeasureSpec.EXACTLY
but it doesnt work either.
The content of textView of the RelativeLayout is dynamic, so i cant
know the width or height of the text. Besides of the exception, if i
manually set enough size on the measure function (insted of 0), my
dynamic text doesnt display entirely. I hope you can help me because
im actually stuck. Thank you, master of developing :).
If you need any more information, let me now please.
--
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