2011-10-12 84 views
3

我创建了我的自定义吐司消息的布局,我将fill_parent设置为我自定义布局的根元素,但布局的大小仍然比整个屏幕小很多。如何使自定义的吐司消息采取整个屏幕

是否可以设置的Toast消息的大小采取整个屏幕?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/toast_layout_root" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" android:gravity="center" > 
    <ImageView android:id="@+id/image" 
       android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_margin="10dip"/> 
</LinearLayout> 

注意android:layout_width =“fill_parent”和android:layout_height =“fill_parent”属性。但我的布局仍然在屏幕的三分之一左右。 。 。

任何意见或建议我该如何让敬酒采取整个屏幕?

回答

5
toast.setGravity(Gravity.FILL_HORIZONTAL|Gravity.FILL_VERTICAL, 0, 0); 
3

认为你需要设置这个调用敬酒时:

Toast myToast = Toast.makeText(this, "Hello", Toast.LENGTH_SHORT); 
myToast.setGravity(Gravity.FILL_HORIZONTAL, 0, 0); 

记不太清楚了,你就需要把管道字符再加入Gravity.FILL_VERTICAL。