I want to see the sum of textview's height and of textview's padding. I set padding with method:
textView.setPadding(0,x,0,x);
But if I use
textView.getHeight();
I will receive 0.
If I use
ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) textView.getLayoutParams();
Log.d(TAG,params.height+"");
I will receive -2 that's impossible.
What have I to do?
Edit: This is the XML code
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/try"
android:textColor="#fff"
android:id="@+id/tv"
android:gravity="center_horizontal" />
Edit2: I use this code for setting width of text view and it work correctely.
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
final int width = size.x;
final int height = size.y;
ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) textView.getLayoutParams();
params.width = width/2;
I don't want to set the height programmately because I set a padding. But I want to get the measure
Edit3:
I try to use
Rect bounds = new Rect();
textView.getPaint().getTextBounds(textView.getText(), 0,textView.getText().length(), bounds);
bounds.height(); //This should give you the height of the wrapped_content
as Slartibartfast told me. But there is a problem:
Probably this is the measurement of text size... But it isn't the correct measurement of height of textview. I tried to sum this number and the 2 measure of padding and try to set:
params.height = bounds.height() + 2*x;
The view is smaller than the view without this line of code.