I want to get the position of my ImageView
programmatically. By position, I mean the distance in pixel from top of the screen to that ImageView.
I have tried every other solution posted in stackoverflow but it's not working for me. My minimum API level is 8.
These are the codes I have tried-
ImageView image = (ImageView) findViewById(R.id.imageView1);
1) image.getTop();
2) private int getRelativeTop(View myView) {
if (myView.getParent() == myView.getRootView())
return myView.getTop();
else
return myView.getTop() + getRelativeTop((View) myView.getParent());
}
3) image.getLocationOnScreen(int[] locaiton);