weilah
weilah

Reputation: 483

Android Alertdialog has different size on Emultator and Device

I create and show an Alertdialog that just looks fine in the emulator but looks weird in my device.

This is how it looks like in the emulator:

enter image description here

This is how it looks like in the device:

enter image description here

This is the code that i'm executing to show the dialog:

    AlertDialog.Builder builder;
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);


    View layout = inflater.inflate(R.layout.popup_contact, (ViewGroup) findViewById(R.id.ppc_llContact));
    tbMissatge = (EditText) layout.findViewById(R.id.ppc_tbMissatge);
    builder = new AlertDialog.Builder(this);


    builder.setView(layout);
    ppEnviarMsg = builder.create();


    btEnviar = (Button) layout.findViewById(R.id.ppc_btEnviar);
    btEnviar.setOnClickListener(this);

    ppEnviarMsg.show();


    ppEnviarMsg.getWindow().getAttributes().gravity = Gravity.CENTER;

And here the layout of the popup:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ppc_llContact"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#414145"
        android:orientation="vertical"
        android:gravity="center">

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textColor="#ffffff"
            android:text="@string/ppc_lbContact"
            android:layout_margin="4dp"/>

        <EditText
            android:id="@+id/ppc_tbMissatge"
            android:hint="@string/ppc_tooltipContact"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="2dp" 
            android:inputType="textMultiLine"
            android:gravity="top"
            android:lines="5">
        </EditText>

        <Button android:id="@+id/ppc_btEnviar"
            android:text="@string/ppc_btEnviar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:layout_marginTop="10dp"/>

    </LinearLayout>

Could it maybe be related with Sense? My device is a HTC Desrie S, running ICS and Sense. Have anyone a clue?

Thanks for helping!

Upvotes: 1

Views: 1053

Answers (1)

a.ch.
a.ch.

Reputation: 8380

I think the problem may be here:

View layout = inflater.inflate(R.layout.popup_contact, (ViewGroup) findViewById(R.id.ppc_llContact));

You use some layout ppc_llContact of your Activity to be an "object that provides a set of LayoutParams values for root of the returned hierarchy", which is quite senseless, because this layout won't participate in final hierarchy of the dialog.

Use this instead:

View layout = inflater.inflate(R.layout.popup_contact, null);

Another option is to forcibly set size of the dialog this way:

ppEnviarMsg.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
//FILL_PARENT is an example

Upvotes: 1

Related Questions