I need that in TextView my text should not be centered along the left edge but in the middle ... And Google had many different articles and examples, but I couldn’t find in that it showed how to make the text centered in the middle ... In Word this is done by pressing one button)) Here in the screenshot, the text on the left I need to pull it to the middle ... Who knows how to do this?

enter image description here

    2 answers 2

    Point to TextView

     android:gravity="center" 

    or from code using the method

     textView.setGravity(Gravity.CENTER); 
    • 2
      You must set the 'layout_width' TextView to 'match_parent'. 'gravity = center' centers the content of the block within it, so if the size of the block corresponds to the size of its content, then visually, the centering will not be noticeable. - Daniel Shatz

    Specify android:gravity="center" for the container (any Layout - LinearLayout , RelativeLayout for example) in which your TextView is located.

    This will arrange all the objects in the container so that the distance from their left and right edges to the edges of the container is the same. The content of these objects is not affected.