Whatever issues you have they are unrelated to setX()
or setY()
and pixel density. Anyway setX()
and setY()
expect an amount of pixels. If you look at the source code of setX()
and setY()
you see this:
/**
* Sets the visual x position of this view, in pixels. This is equivalent to setting the
* {@link #setTranslationX(float) translationX} property to be the difference between
* the x value passed in and the current {@link #getLeft() left} property.
*
* @param x The visual x position of this view, in pixels.
*/
public void setX(float x) {
setTranslationX(x - mLeft);
}
/**
* Sets the visual y position of this view, in pixels. This is equivalent to setting the
* {@link #setTranslationY(float) translationY} property to be the difference between
* the y value passed in and the current {@link #getTop() top} property.
*
* @param y The visual y position of this view, in pixels.
*/
public void setY(float y) {
setTranslationY(y - mTop);
}
In other words they basically just call setTranslationX()
and setTranslationY()
. If your View
is unaffected by calls to setX()
and setY()
I would first look for other causes. For example you may be trying to call setX()
and setY()
on the wrong View
or another part of your code later on may overwrite your changes. I cannot give you a more detailed answer than that with the information you provided.