14

私は最近、チュートリアルに従ってカスタムトーストを試しました:

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 は効果がないようです。

フルスクリーンのトーストを取得するためにこれを修正する方法についてのアイデアはありますか?

4

2 に答える 2

23

トーストを表示する前にこれを追加します。

toast.setGravity(Gravity.FILL, 0, 0);
于 2012-10-20T18:35:18.160 に答える
3

トーストをコンテナのサイズで水平および垂直に完全に埋めるには、使用する必要があります

Yoahの回答に記載されているGravity.FILL。

私は以下を試しましたが、うまくいきました。

Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.FILL, 0, 0);
toast.setView(view); //inflated view
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
于 2012-10-20T18:45:08.117 に答える