开发者

Trying to force Activity with Theme.Dialog to fixed width

开发者 https://www.devze.com 2023-02-16 01:46 出处:网络
I always struggle with UI design and this is giving me problems. I have an Activity which uses Theme.Dialog to make it appear as a popup. My problem is I want it to always have max screen width regar

I always struggle with UI design and this is giving me problems.

I have an Activity which uses Theme.Dialog to make it appear as a popup. My problem is I want it to always have max screen width regardless of the child components' widths. In the images below, the dialog width on the left is being forced to maximum by the width of the text in the spinner (I don't mind the spinner text being clipped - I'm just happy with the dialog width and it's how I'd like it to look.

If I change the spinner selection to an option with shorter text however, I get the dialog on the right. Instead of the text being clipped and the spinner forcing max width of the dialog, the text easily fits and the spinner (and dialog) shrink.

My layout is using LinearLayout elements which I'm sure is the main problem but I can't workout what a suitable alternative would be 开发者_Python百科or how to say 'always make the dialog max width'.

Any help greatly appreciated.

Trying to force Activity with Theme.Dialog to fixed width

Trying to force Activity with Theme.Dialog to fixed width


In the onCreate method of your activity, put in the following

getWindow().setLayout (LayoutParams.FILL_PARENT /* width */ , LayoutParams.WRAP_CONTENT /* height */);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号