Yahj Rodriguez Yahj Rodriguez - 5 months ago 28
Android Question

How do I change the position of my new Activity (Display Metrics)

EDIT: The application's interface

I've created a Pop-up window and class that when I click this onInfoWindowClick in the google maps, a pop-up window will appear OR the next activity will appear. I used Display Metrics for this but it only shows up in the center screen.

What I want to happen is: when the activity shows up, I would like it to show up in the upper-top or at least have the power to change the position of the activity in any part of the window.

My problem: The display metrics shows the activity only in the center.

My codes in my Pop-Up window:

public class PopUp extends AppCompatActivity {
protected void onCreate(@Nullable Bundle savedInstanceState) {


DisplayMetrics dm = new DisplayMetrics();

int width = dm.widthPixels;
int height = dm.heightPixels;



Note: Is there an another method to do this? Can you give me link on how to do it. (Only if there is an another method to do it)

Answer Source

Just add this line at the end:


P.S. you can use other values (not only Gravity.TOP) according to your needs. Also you can combine multiple options, for instance, getWindow().setGravity(Gravity.TOP|Gravity.START);