具有动态内容的布局警报对话框 - 结果太高
我很难挤压我的警报对话框来包装我的内容。 对话框的布局 xml 的结构如下:
+ linear layout (main)
++ text view
++ linear layout (placeholder)
我使用占位符稍后在 oncreate 期间通过调用 addView() 向其附加一个单独的 edittext 派生字段,因此我的 onCreate 基本上如下所示:
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
结果是:警报对话框的高度是其应有高度的两倍。我的线性布局设置为 WRAP_CONTENT 高度,如果我绘制它们的背景,我会看到它们的大小正确(几乎是对话框高度的一半)。对话框的其余部分是黑色的,因此没有任何组件强制或期望这个大小。
我将文本的 maxLines 设置为 1,但这又没有任何帮助。这似乎是一个微不足道的布局问题,但我不知道我还应该调用什么来让对话框挤压以简单地包装内容。
谢谢大家的任何提示。
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 it, 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置
maxLength
,您可以使用ellipsize
来指示连续的文本。set
maxLength
and you can useellipsize
to indicate the text in continuation..