center textview programmatically android

Java
yourTextView.setGravity(Gravity.CENTER);
Source

Also in Java: