How to detect width of TextView that has attribute wrap_content?
I have a layout with element TextView
<TextView android:textColor="#ffffff" android:text="18 августа"
android:id="@+id/program_day1" android:layout_gravity="center"
android:textSize="18sp" android:textStyle="bold"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_weight="1" android:gravity="center" />
How can I detect the real size (and margins)开发者_StackOverflow of this in the onStart (or other) event? Now it shows "-2" values
try with myTextView.getPaint().measureText(myTextViewtext) it didn't return the size of the view but the size of the text,hope it could help you
Views don't get height or width until they are actually drawn on screen.
Try to show the width in the onSizeChanged
function. Check if a real size will be shown. Use getwidth
.
Apart from that, you can use TextView.getWidth()
and Textview.getHeight()
to get w/h and
LayoutParams lp = (LayoutParams) TextView.getLayoutParams();
to get margin values
精彩评论