I have a dialog with a custom style that's using a layout that I defined in an XML file. I'd like this dialog to fill the width of the screen in portrait mode, but only about 400dip in landscape mode. MaxWidth seems to be the perfect way to accomplish that, but I can't figure out how to assign a MaxWidth to the dialog style or the XML layout.
Assuming you use next layout file called layout/dialog_core.xml
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
//All your dialog views go here....
</LinearLayout>
You can then create two more files: layout/dialog.xml
and layout-land/dialog.xml
.
The layout/dialog.xml
file will not limit the width:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
<include layout="@layout.dialog_core.xml" />
</LinearLayout>
While your layout-land/dialog.xml
should have width limitation:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:maxWidth="400dp" >
<include layout="@layout.dialog_core.xml" />
</LinearLayout>
And of course, you need to use R.layout.dialog
layout in your code now.
P.S. I used LinearLayout
for example purposes only. Any layout view will do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With