There is an xml in which the following LinearLayout included:
portion_picker.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="64dp" android:gravity="center" android:orientation="horizontal"> <ImageButton android:id="@+id/portion_minus" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:src="@drawable/ic_minus"/> <TextView android:id="@+id/potion_count_text_view" android:layout_width="64dp" android:layout_height="wrap_content" //64dp android:text="0" android:textSize="54sp" android:gravity="center"/> <ImageButton android:id="@+id/portion_plus" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:src="@drawable/ic_plus"/> </LinearLayout> The preview looks correct:
But on real devices (SGS5, Note 3), the TextView displays the text inside (in my case, the truth is just one / two digits) incorrectly - as you can see - not in the center (relative to the horizontal axis), but slightly lower, I think it is noticeable and hurts the eye.
Why does the text shift inside? In such a mapping, this is very critical, I ask you to tell why this offset occurs.


android:gravity="center_vertical"forTextView- YuriySPb ♦