Question: I am trying to get the view position (Right upper corner position and left bottom corner position) and display custom dialog right or left side of view but i am not getting exact position of view. This is my code

```
    int x=view.getLeft()+  (view.getHeight()*4);
    int y= view.getBottom()+(view.getWidth()*2);
    showDialog(x,y,Gravity.TOP,Gravity.LEFT);`  

    public void showDialog(int x, int y,int gravity_y,int gravity_x){
    final Dialog dialog  = new Dialog(this, R.style.ActivityDialog);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    dialog.setContentView(R.layout.cofirm_sell);
    dialog.setCanceledOnTouchOutside(false);
    WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
    dialog.getWindow().getAttributes().windowAnimations=R.style.DialogTheme;
    wmlp.gravity = gravity_y | gravity_x;
    wmlp.x = x;
    wmlp.y = y;
    ImageButton close=(ImageButton)dialog.findViewById(R.id.close);
    close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    dialog.show();

```

}

I want this

[![enter image description here](https://i.stack.imgur.com/HW5Cq.png)](https://i.stack.imgur.com/HW5Cq.png)

Answer: 
Check this:

```
    int[] outLocation = new int[2];
    view.getLocationOnScreen(outLocation);
    Rect rect = new Rect(
            outLocation[0],
            outLocation[1],
            outLocation[0] + view.getWidth(),
            outLocation[1] + view.getHeight());
    //right upper corner rect.right,rect.top 
    //left bottom corner rect.left,rect.bottom

```
Thanks to @Sree, in Kotlin:

```
val location = IntArray(2)
view.getLocationInWindow(location)

val left = location[0]
val right = left + view.width
val top = location[1]
val bottom = top + view.height

```