views:

509

answers:

1

I made a custom alert dialog box to be displayed at the end of my game so that the player can enter its name to save it. The problem is when I call show() on the dialog appears but it's not vertically centered! It's a bit lower than it should and no matter what properties I set in the xml or when using setGravity().

I think it's the same problem as stated here: http://bit.ly/9tk0ld but no one gave a proper answer.

Thanks for your help.

here is my code for more detail:

    AlertDialog.Builder builder;

    LayoutInflater inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.newrecord,(ViewGroup)findViewById(R.layout.shoot));

    builder = new AlertDialog.Builder(this);
    builder.setView(layout);

    newRecDialog = builder.create();

And here is the code of the first element of the XML layout of newrecord.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:gravity="center"
 android:padding="10dp"
android:baselineAligned="true">

Here is the output screenshot: alt text

A: 

set the attribute on your AlertDialog as android:gravity="center" or programmatically as setGravity(Gravity.CENTER). This Gravity is for your layout only not for the display of your mobile. if you use Custom Title its did not look like center vertical.

Praveen Chandrasekaran
I tried all this already and it doesn't work. My XML file is actually the description of the content of the dialog box which I inflate, is this wrong ?
NioX5199
I cant get you properly. But Any way the content of the view does not affect the gravity. so please post your code. i shall try.
Praveen Chandrasekaran
@NioX5199: can you post your output's Screen shot?
Praveen Chandrasekaran
Thanks for your replies, I added a screenshot.
NioX5199
@NioX5199: try `builder.setGravity(Gravity.CENTER);` on your java code. It works.
Praveen Chandrasekaran
Ok, I tried this, but it tells me that the method setGravity is not defined for AlertDialog.Builder :S
NioX5199
There is no setGravity method for AlertDialog.builder
Donal Rafferty