android - Why does SetGravity onToast have no effect? -


i have activity tries create custom toast object. toast show in center of screen no matter set gravity be, toast shows @ top. looks settings give toast have no effect on happens. can move toast center.

the code create toast:

layoutinflater inflater = (layoutinflater) context.getsystemservice                             (context.layout_inflater_service); relativelayout layout = (relativelayout) inflater.inflate(r.layout.notification_layout,null);  ((textview) layout.findviewbyid(r.id.title)).settext(title); ((textview) layout.findviewbyid(r.id.content)).settext(content); toast toast = new toast(this);  toast.setduration(toast.length_short); toast.setgravity(gravity.center, 0, 0); toast.setview(layout); toast.show(); 

the xml layout inflating:

<?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="100dp"     android:id="@+id/notificationtoast">      <imageview         android:layout_width="50dp"         android:layout_height="50dp"         android:src="@drawable/ic_launcher"         android:layout_alignparenttop="true"         android:layout_alignparentstart="true"         android:id="@+id/imageview4" />      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textappearance="?android:attr/textappearancelarge"         android:text="title"         android:id="@+id/title"         android:gravity="center"         android:layout_alignbottom="@+id/imageview4"         android:layout_alignparenttop="true"         android:layout_alignparentend="true"         android:layout_toendof="@+id/imageview4" />      <textview         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:textappearance="?android:attr/textappearancemedium"         android:text="content"         android:id="@+id/content"         android:layout_below="@+id/imageview4"         android:layout_alignparentstart="true"         android:layout_alignparentbottom="true"         android:layout_alignparentend="true" /> </relativelayout> 

the height of layout toast inflating in 100dp. center variable puts toast in center of parent layout. make height of parent layout the entire screen (match_parent). when call setgravity(gravity.center, 0, 0) in center of screen aka center of parent layout.

toast: http://developer.android.com/reference/android/widget/toast.html gravity: http://developer.android.com/reference/android/view/gravity.html


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -