AppCompatTextView gravity center not working in android 20 (KitKat)

Viewed 362
<androidx.appcompat.widget.AppCompatTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:layout_alignTop="@+id/iv_security_code"
            android:layout_alignBottom="@+id/iv_security_code"
            app:drawableLeftCompat="@drawable/ic_refresh_black_24dp"
            android:gravity="center" />

This issue comes in android 20 version (KitKat) and working fine for Lolipop version devices.

Issue is, the tag android:gravity="center" is not working as expected. Check this image : enter image description here

Got the hack to fix this issue: After changing android:layout_height="wrap_content" to some particular height and then it works. But still, this issue needs to be fixed.

2 Answers

I think in your case, you should make the height of the textView to match_parent.

If you don't want to do that, you should then set the layout_gravity="center".

Hey if you want the view on the center then use android:layout_gravity="center" and if you want to center the text then use android_gravity="center"

Related