Solution 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;
}
});
Problem :
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.
Comments
Comment posted by minimal reproducible example
“I tried getLocationOnScreen but it is giving me 0” — that may be a matter of timing. You should consider adding a
Comment posted by AroshiS
@CommonsWare, added the code snippet
Comment posted by AroshiS
thanks for your answerr. But will this work without any user action ?