In android, how to make empty TextView stay in the middle vertically? -


in android, want add empty message in middle of screen when gridview empty. layout below makes text in middle-top of screen. how can make text in middle in vertical direction ?

gridview gridview = (gridview) findviewbyid(r.id.gridview);         textview emptytext = (textview)findviewbyid(r.id.empty); gridview.setemptyview(emptytext);       <?xml version="1.0" encoding="utf-8"?>     <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"         android:orientation="vertical"         android:layout_width="match_parent"         android:layout_height="match_parent">       <gridview xmlns:android="http://schemas.android.com/apk/res/android"        android:id="@+id/gridview"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:columnwidth="100dp"        android:numcolumns="auto_fit"        android:verticalspacing="10dp"        android:horizontalspacing="10dp"        android:stretchmode="columnwidth"         android:paddingtop="?android:attr/actionbarsize"        android:gravity="center"         />           <textview         android:id="@+id/empty"         android:layout_width="wrap_content"         android:layout_height="wrap_content"             android:layout_gravity="center"          android:gravity="center"         android:text="no project files found"         android:textcolor="#ffffff" />       </linearlayout> 

make parent view relativelayout , set centerinparent="true" textview

<?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"     android:background="@color/grey">      <textview         android:layout_centerinparent="true"         android:layout_width="match_parent"         android:layout_height="match_parent" />  </relativelayout> 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -