-1

I am trying to get coordinates of frame layout present in my screen in android. I tried getLocationOnScreen but it is giving me 0. How to get the right value?

  int[] location = new int[2];
  face_oval_layout.getLocationOnScreen(location);
  Util.log("X axis is " + location[0] + "and Y axis is " + location[1]);

Above snippet called inside camera take picture callback. Value of X and Y, both are 0.

AroshiS
  • 79
  • 1
  • 9
  • 2
    "I tried getLocationOnScreen but it is giving me 0" -- that may be a matter of timing. You should consider adding a [mcve] to your question, showing where and how you are trying to call `getLocationOnScreen()`. – CommonsWare Aug 08 '20 at 14:29
  • @CommonsWare, added the code snippet – AroshiS Aug 08 '20 at 14:33

1 Answers1

-1
frmLayout = (FrameLayout)findViewById(R.id.frameLayout1);
    frmLayout.setFocusable(true);
    EditText et = new EditText(this);

    frmLayout.addView(et,100,100);
    frmLayout.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Log.i("TESTING","touch x,y == " + event.getX() + "," +     event.getY() );
            frmLayout.setPadding(Math.round(event.getX()),Math.round(event.getY()) , 0, 0);
        return true;
    }
});
Muhammad Asad
  • 694
  • 6
  • 10