Center Align Android TextView Text


Center Align Text in TextView Android

To center align the Text in a TextView we can name use of the property android:textAlignment="center", let us see an example where we have a with layout width as fill_parent and height as wrap_content and the text is center aligned.


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textAlignment="center"
        android:id="@+id/myTextView"/>
</LinearLayout>


Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org



















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap