setX()
无论您遇到什么问题,它们都与orsetY()
和像素密度无关。无论如何setX()
,setY()
期待一定数量的像素。如果您查看源代码setX()
并setY()
看到以下内容:
/**
* 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);
}
换句话说,他们基本上只是调用setTranslationX()
and setTranslationY()
。如果您View
的电话没有受到影响,setX()
我setY()
会首先寻找其他原因。例如,您可能正在尝试调用错误setX()
,或者稍后代码的另一部分可能会覆盖您的更改。我不能给你比你提供的信息更详细的答案。setY()
View