Loading...

Programmatically Align Android TextView in the Center of the Screen

Android TextView allows user to display text in android application. In this simple tip, I am going to show how to programmatically align android TextView in the center of the screen. To display text in the center of screen programmatically you have to use .setGravity(Gravity.CENTER) method.

Related:
How to Make Scrollable TextView in Android
How to Set Android Button and TextView Border Color
Android Material Design with Design Support Library

Android Example: How to Align Android TextView in the Center of the Screen


XML Layout File

Your XML layout file looks like this.
res/layout/textview_center.xml

Java Activity File

And your java activity file code looks like this.
src/MainActivity.java

Now, run your application which looks like this.

Programmatically Align Android TextView in the Center of the Screen
Android TextView in the Center

Tutorial 6436834477710700316
Home item