android set text alignment programmatically code example Example: center textview programmatically android yourTextView.setGravity(Gravity.CENTER);