Get Available Width For Textview With Layout_width="wrap_content"
I have a complex layout that has TextView with layout_width='wrap_content'. I want to get maximum width that this TextView can fill. Is there a universal way to do it? Or should I
Solution 1:
You can get it's parent and calculate it's width like this. This width would be the maximum width the TextView can take provided the parent has no padding.
View parent = (View) textView.getParent();
int width = parent.getWidth();
If the parent has some padding you'll need to compute it separately and subtract from this width.
int paddingE = parent.getPaddingEnd();
int paddingS = parent.getPaddingStart();
int totalWidth = width - (paddingE + paddingS);
Post a Comment for "Get Available Width For Textview With Layout_width="wrap_content""