I have a method that shows an error message. Now the field comes out at the very top in the middle, and how to make it crawl a little below the very top and also in the middle?

public void oshibka () { Toast problem = Toast.makeText(MainActivity.this, ss, Toast.LENGTH_SHORT); problem.setGravity(Gravity.TOP, 0, 0); problem.show(); } 

enter image description here

    1 answer 1

    You write Gravity.TOP , therefore at the very top. Write Gravity.CENTER (will be in the middle of the screen) and manually select the offset that you need.

    For example:

     problem.setGravity(Gravity.TOP, 0, 20); 

    The possible values ​​for the Gravity parameter are: documentation .

    Disadvantages of the setGravity method: it accepts integers as an offset, which indicate the number of pixels. Therefore, the vertical offset 200 on the 480x800 screen will be a quarter of the screen, and on the screen 2160x3840 these 200 pixels will not be noticed. You can use the setMargin () method. He sets the relative offset of the toast. These options will bring the toaster below the middle of the screen:

     problem.setMargin(0, (float) 0.33);