Programmatically Align Android TextView in the Center of the Screen
http://www.viralandroid.com/2015/11/programmatically-align-android-textview-in-the-center-of-screen.html
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
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.
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.
Android TextView in the Center |