Android AlertDialog not centering/scaling vertically
I'm building an AlertDialog that contains a custom View like so:
@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);
}
And the layout 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"
a开发者_高级运维ndroid:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dip"
android:text="@string/intro_add"
android:textColor="#FFFFFF" />
</TableRow>
<!-- ... -->
</TableLayout>
</ScrollView>
That gives me a dialog that looks something like this (details blurred, sorry):
The problem is that big gap at the top (above the dialog). Is there anything I can do to either get rid of it or make the bottom have a similar gap?
The bug is described here: http://code.google.com/p/android/issues/detail?id=11824. The AlertDialog is reserving space for the title/icon panel even where there is neither a title nor an icon.
The fix is, I think, quite simple: it should set the top panel layout to GONE, just as it does for the button panel in the event of there being no buttons. Until that's done, the only workaround is to implement your own Dialog subclass.
Turns out it's a bug (kinda). You have to just implement your own Dialog to make it work right.
精彩评论