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.
In the onCreate method of your activity, put in the following
getWindow().setLayout (LayoutParams.FILL_PARENT /* width */ , LayoutParams.WRAP_CONTENT /* height */);
精彩评论