In my case, I tried to use android:layout_centerHorizontal="true", as suggested in this thread, to display text when the AdapterView (ListView, GridView, etc.) is empty, but this did not work:
The solution was to use instead android:layout_centerVertical="true".
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolsGridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
<TextView
android:id="@+id/emptyGridViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"
android:padding="12dp"
android:text="Not items to display at the moment. Please check again soon"
android:textColor="@color/colorAccent"
android:textSize="15sp"/>
</RelativeLayout>
do not forget to use android:gravity="center"to align text correctly

source
share