如何改变在Android的吐司的位置?吐司、位置、Android

2023-09-12 00:07:15 作者:爱他们的时候我们像条狗

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

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.

 
精彩推荐
图片推荐