Webview
Android用の簡単なアプリケーションを作成しています。接続がない場合、画面全体をカバーするカスタム トースト メッセージを表示していますが、トースト内にImageView
. 問題は、次のコードを使用してトーストを実行しているため、トーストが画面全体を覆っていることです。
toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.FILL_VERTICAL, 0, 0);
ImageView
トーストの内側を完全に中央に配置するにはどうすればよいですか? これはImageView
、次の名前のトースト レイアウトにありますtoast_custom_layout.xml
。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:orientation="horizontal"
android:padding="5dp" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo"
android:background="@color/white" />
</LinearLayout>
これは、接続がないときにトーストを表示するアクティビティのコードです。
public void onReceivedError(WebView view, int errorCode,String description, String failingUrl) {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_custom_layout,
(ViewGroup) findViewById(R.id.toast_layout_root));
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.FILL_VERTICAL, 0, 0);
}
アドバイスをいただければ幸いです。