tags:

views:

1698

answers:

1

Hi,

I can create and display a custom alert dialog just fine but even so I have android:layout_width/height="fill_parent" in the dialog xml it is only as big as the contents.

What I want is dialog that fills the entire screen except maybe a padding of 20 pixel. Then the image that is part of the dialog would automatically stretch to the full dialog size with fill_parent.

Thanks a lot, Fabian

+3  A: 

Set android:minWidth and android:minHeight in your custom view xml. These can force the alert not to just wrap content size. Using a view like this should do it:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:minWidth="300dp" 
  android:minHeight="400dp">
  <ImageView
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:background="@drawable/icon"/>
</LinearLayout>
jqpubliq
Yes with this I can set it to a specific size, but I want it to be screensize minus a padding of e.g. 20 pixel. Or width = 90% of screenwidth.
Fabian
I density independent pixels are always scaled so that any screen is 320x480dp so a 300x460dp view would be a 20dp padding in all cases. Alternatively you could find the size of the screen like this: Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int width = display.getWidth(); and set maxWidth and maxHeight accordingly.
jqpubliq
Hmm from the decoumentation I understand the concept of dp.But what if the screen ratio is 16:9 or 4:3? Will th dp be stretched unevenly?
Fabian