In my app, I have a button that creates a TextView with a certain message. How can I set the text alignment of the text to the right of the TextView? I see the attribute in XML, but I don't know how to do it in java.
In Kotlin you can use something like the below,
val textView = TextView(context)
textView.apply {
layoutParams = TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT)
textAlignment = View.TEXT_ALIGNMENT_VIEW_START
}
Try using
textView.setGravity(Gravity.RIGHT)
You can set textview's gravity using
textLabel.setGravity(Gravity.CENTER | Gravity.BOTTOM);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With