我正在爲Android創建一個簡單的Webview
應用程序。當沒有連接時,我顯示一個自定義的烤麪包信息,它將覆蓋所有的屏幕,但在烤麪包片中,我想用ImageView
顯示圖像。問題是,在吐司覆蓋所有屏幕,因爲我使用下面的代碼來做到這一點:Android中Toast中的ImageView中心
toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.FILL_VERTICAL, 0, 0);
怎麼可能我把烤麪包片內ImageView
完全居中?這是一個名爲toast_custom_layout.xml
敬酒佈局ImageView
:
<?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);
}
我會非常感謝你的建議,朋友。
使用的RelativeLayout及其layout_centerInParent屬性... – yahya 2013-03-06 20:32:54
感謝葉海亞,這個工作整齊! – 2013-03-06 21:44:08