2012-10-20 94 views
11

我已經recentrly嘗試定製吐司教程如下:創建全屏自定義吐司

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

在這種佈局:

<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> 

但似乎在根佈局FILL_PARENT沒有效果。

你有什麼想法可以解決這個問題,以獲得全屏吐司?

回答

19

告訴你敬酒前補充一點:

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

完全填滿舉杯水平和垂直在其容器的大小,你需要使用

Gravity.FILL在Yoah的答覆中提到。

我試着跟着它工作。

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