开发者

Layout alert dialog with dynamic content - result too tall

开发者 https://www.devze.com 2023-04-02 13:03 出处:网络
i\'m having a hard time squeezing my alert dialog to just wrap my content. the dialog\'s layout xml is structured like this:

i'm having a hard time squeezing my alert dialog to just wrap my content. the dialog's layout xml is structured like this:

+ linear layout (main)
++ text view
++ linear layout (placeholder)

i use the placeholder to attach a singe edittext-derived field to it later, during oncreate, by calling addView() on i开发者_JAVA技巧t, so my onCreate basically looks like this:

View v = LayoutInflater.from(context).inflate(input_layout, null);
LinearLayout placeholder = (LinearLayout)view.findViewById(input_placeholder)
SoftEditText text = new SoftEditText(context)

// set text attributes - input type, ime action, watchers and listeners

placeholder.addView(text);
setCancelable(true);
setButton(BUTTON_NEGATIVE, ....);
setTitle(title_label);

// view.forceLayout() - didn't help much

setView(view);
super.onCreate(instance);

// getWindow().getAttributes().height=LayoutParams.WRAP_CONTENT no go either

and the result is: my alert dialog is twice the height it's supposed to be. my linearlayout's are set to WRAP_CONTENT height, and if i paint their background, i see they are of correct size (that is nearly half the dialog's height). the rest of the dialog is black, so there is no component that forces or expects this size.

I set the text's maxLines to 1, but that again hasn't helped at all. this seems to be a trivial layout problem but i can't figure out what more should i call to get the dialog squeeze to simply wrap the content.

thanks bunches for any tip.


set maxLength and you can use ellipsize to indicate the text in continuation..

0

精彩评论

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

关注公众号