如何改变在Android的吐司的位置? [英] How to change position of Toast in Android?

查看:269
本文介绍了如何改变在Android的吐司的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用吐司来在屏幕上显示一些弹出的文本,它会显示文字一点点屏幕上方的底部,这是默认的位置。

When I use Toast to display some popup text on the screen, it displays the text a little bit above the bottom of the screen, which is the default position.

现在我想在屏幕中间显示,或地方根据自己的选择。

Now I want to display it in the middle of screen or somewhere according to my choice.

任何人都可以指导我如何实现这一目标?

Can anyone guide me how to achieve this?

推荐答案

的文件

定位你的吐司

一个标准T​​oast通知出现在屏幕的底部附近,   水平居中。您可以更改这个位置与    setGravity(INT,INT,INT)方法。这个接受三个参数:   重力常数, x位置偏移,和 Y位置偏移。

A standard toast notification appears near the bottom of the screen, centered horizontally. You can change this position with the setGravity(int, int, int) method. This accepts three parameters: a Gravity constant, an x-position offset, and a y-position offset.

例如,如果你决定,敬酒应该出现在   左上角,你可以设置重力是这样的:

For example, if you decide that the toast should appear in the top-left corner, you can set the gravity like this:

toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);

如果要轻推姿势要正确,增加的价值   第二个参数。轻推下来,增加了最后的值   参数。

If you want to nudge the position to the right, increase the value of the second parameter. To nudge it down, increase the value of the last parameter.

这篇关于如何改变在Android的吐司的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆