[英]Android AlertDialog not centering/scaling vertically
我正在構建一個包含自定義視圖的AlertDialog,如下所示:
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_INTRO:
// setup the dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View inflatedLayout = ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE)).inflate(R.layout.intro, null);
builder.setView(inflatedLayout);
// return the dialog
return builder.create();
}
return super.onCreateDialog(id);
}
以及布局XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
<TableLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:stretchColumns="2"
android:shrinkColumns="1">
<TableRow>
<TextView
android:id="@+id/intro_TextView_title"
android:layout_height="wrap_content"
android:layout_span="2"
android:gravity="center"
android:text="@string/intro_title"
android:textSize="22sp"
android:textColor="#FFFFFF" />
</TableRow>
<TableRow
android:layout_marginTop="20dip" >
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="25dip"
android:layout_marginRight="25dip"
android:paddingTop="2dip"
android:src="@drawable/intro_add" />
<TextView
android:id="@+id/intro_TextView_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dip"
android:text="@string/intro_add"
android:textColor="#FFFFFF" />
</TableRow>
<!-- ... -->
</TableLayout>
</ScrollView>
這給了我一個看起來像這樣的對話框(細節模糊,抱歉):
問題是頂部(對話框上方)的差距很大。 我有什么辦法可以擺脫它或讓底部有類似的缺口?
該錯誤的描述如下: http : //code.google.com/p/android/issues/detail?id=11824 。 即使沒有標題也沒有圖標,AlertDialog仍為標題/圖標面板保留空間。
我認為解決方法很簡單:應該將頂部面板的布局設置為GONE,就像在沒有按鈕的情況下對按鈕面板的設置一樣。 在完成此操作之前,唯一的解決方法是實現自己的Dialog子類。
原來這是一個錯誤(有點)。 您只需要實現自己的對話框即可使其正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.