2012-10-20 17 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(); 
संबंधित मुद्दे