小编CRO*_*M87的帖子

measure()无法正常使用动态布局和textView - Android

我想将RelativeLaout视图转换为Bitmap.我尝试了另一个答案和不同的选择但没有成功.我的XML视图有点像:

----RelativeLayout
-------ImageView
-------TextView

每个人都有wrap_content措施.

因为我需要视图的几个位图,所以我这样膨胀它:

  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;

之后 :


//in measure() i get a nullpointerException on RelativeLayout.onMeasure().I also have tried //with MeasureSpec.EXACTLY
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);                   

RelativeLayout的textView内容是动态的,所以我不知道文本的宽度或高度.除了例外,如果我在测量功能上手动设置足够的尺寸(输入为0),我的动态文本就不会完全显示.我希望你能帮助我,因为现在,我卡住了.谢谢youuu

android bitmap dynamic textview measure

8
推荐指数
1
解决办法
4654
查看次数

标签 统计

android ×1

bitmap ×1

dynamic ×1

measure ×1

textview ×1