2012-10-20 5 views
11

Ich habe Erstellen recentrly eine benutzerdefinierte Toast nach dem Tutorial versucht:einen Vollbild-Gewohnheit Toast

http://developer.android.com/guide/topics/ui/notifiers/toasts.html#CustomToastView

Mit einem solchen Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/toast_layout_root" 
       android:orientation="horizontal" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:padding="8dp" 
       android:background="#DAAA" 
       > 
    <ImageView android:src="@drawable/droid" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="8dp" 
       /> 
    <TextView android:id="@+id/text" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="#FFF" 
       /> 
</LinearLayout> 

Aber es scheint, dass die fill_parent im Stammlayout hat keine Wirkung.

Haben Sie eine Idee, wie ich das beheben kann, um Fullscreen Toast zu bekommen?

Antwort

19

diese hinzufügen, bevor Sie den Toast zeigen:

toast.setGravity(Gravity.FILL, 0, 0); 
1

vollständig Um einen Toast horizontale und vertikale Größe des Containers füllen Sie brauchen

Gravity.FILL zu verwenden, wie in Yoah Antwort erwähnt.

Ich habe versucht, zu folgen und es hat funktioniert.

Toast toast = new Toast(getApplicationContext()); 
toast.setGravity(Gravity.FILL, 0, 0); 
toast.setView(view); //inflated view 
toast.setDuration(Toast.LENGTH_LONG); 
toast.show();