Can you please tell me how to align the text in the center of the TextView in height? How does Gravity.CENTER work for me? As seen in the text on a black TextView, the text aaaaa is not symmetrical.

<TextView android:id="@+id/textView" android:layout_width="150dp" android:layout_height="28dp" android:text="aaaaa" android:gravity="center_vertical" android:background="#000000" android:textColor="#ffffff"/> 

enter image description here

  • center_horizontal for gravity and paddingTop calculate, if you do not plan to change the textView size, and if you plan, you can programmatically change, but still crutches - Alex Tremasov
  • It is impossible to calculate the paddingTop correctly, since there are some indents inside the textView .. This is how it does not work out correctly: int padd_top; Rect bounds = new Rect (); textView.getPaint (). getTextBounds (textView.getText (). toString (), 0, textView.getText (). length (), bounds); padd_top = (textView.getMeasuredHeight () - bounds.height ()) / 2; - Alex455 4:18 pm
  • How to calculate the paddingTop? - Alex455
  • four
    It is symmetrical because there can be uppercase letters. - Style-7
  • Style-7, so the fact is that the question is what should be aligned on the basis of the text, now these letters are not with upper case letters or numbers ... - Alex455

0