This has been driving me crazy for the past couple of hours.
I have a FrameLayout, that has a single button on it.
When you click the button, I want to draw a new word, and get it's measurements so I can draw a rectangle around it.
This is the code that runs when you click on the 'Next' button:
private OnClickListener m_onClickNext = new OnClickListener()
{
public void onClick(View v)
{
TextView tv = new TextView(context);
tv.setTextColor(0xFF000000);
tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 100);
tv.setText("TEXTSTRING");
m_frameLayout.addView(tv, new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER));
//tv.measure(0, 0);
int left = tv.getLeft();
int top = tv.getTop();
int right = left + tv.getMeasuredWidth();
int bottom = top + tv.getMeasuredHeight();
}
};
left and top are 0 (zero).
Adding tv.measure(0, 0)
atleast updates the width and height.
I tried calling invalidate
and requestLayout
on tv
and m_frameLayout
, with no success.
I understand the layout hasn't finish drawing.. but WHY ????