简体   繁体   English

Android对话框或浮动活动偏离中心

[英]Android dialog or floating activity off-center

Is it possible to have an Android Alert box or Dialog off-center? Android警报框或对话框是否可能偏离中心? I have tried everything that comes to mind, including making a custom Dialog activity and theme (extending Android:Theme.Dialog), but I have not been able to move it from it's centered position. 我已经尝试了所有想到的方法,包括制作自定义Dialog活动和主题(扩展了Android:Theme.Dialog),但是我无法将其从居中位置移开。

Yes you can make the background translucent and fill the entire view, then nest a visible layout within that you can use layout_gravity="top|left" on. 是的,您可以使背景透明并填充整个视图,然后在其中嵌套可见的布局,并可以使用layout_gravity =“ top | left”。

A little off topic, but if you just want to display text, an easier way is to use a toast. 有点不合时宜,但是如果您只想显示文本,则更简单的方法是使用烤面包。

Toast toast = new Toast(new ContextThemeWrapper(getApplicationContext(), R.style.YourDialogStyle));
toast.setGravity(Gravity.LEFT|Gravity.TOP, 0,0);

PopupWindow ? PopupWindow An example can be found here: http://www.anddev.org/how_to_create_a_popupwindow-t1259.html 可以在以下示例中找到: http : //www.anddev.org/how_to_create_a_popupwindow-t1259.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM