View: implement setTranslation{X,Y}

This commit is contained in:
Mis012
2025-10-23 17:44:07 +02:00
parent 451e23fcd2
commit 3247ae20f6
2 changed files with 36 additions and 13 deletions

View File

@@ -610,6 +610,12 @@ JNIEXPORT void JNICALL Java_android_view_View_native_1layout(JNIEnv *env, jobjec
allocation.width = width; allocation.width = width;
allocation.height = height; allocation.height = height;
} }
if (wrapper->jobj) {
allocation.x += _GET_FLOAT_FIELD(wrapper->jobj, "translationX");
allocation.y += _GET_FLOAT_FIELD(wrapper->jobj, "translationY");
}
gtk_widget_size_allocate(widget, &allocation, -1); gtk_widget_size_allocate(widget, &allocation, -1);
} }

View File

@@ -872,10 +872,13 @@ public class View implements Drawable.Callback {
int measuredWidth = 0; int measuredWidth = 0;
int measuredHeight = 0; int measuredHeight = 0;
private int left; private int left = 0;
private int top; private int top = 0;
private int right; private int right = 0;
private int bottom; private int bottom = 0;
private float translationX = 0;
private float translationY = 0;
private int scrollX = 0; private int scrollX = 0;
private int scrollY = 0; private int scrollY = 0;
@@ -1711,13 +1714,24 @@ public class View implements Drawable.Callback {
return viewPropertyAnimator; return viewPropertyAnimator;
} }
public float getTranslationX() {return 0.f;} public float getTranslationX() {
public float getTranslationY() {return 0.f;} return translationX;
public void setTranslationX(float translationX) {} }
public float getTranslationY() {
return translationY;
}
public void setTranslationX(float translationX) {
this.translationX = translationX;
if (parent instanceof View)
((View)parent).native_queueAllocate(((View)parent).widget);
}
public void setTranslationY(float translationY) { public void setTranslationY(float translationY) {
// CoordinatorLayout abuses this method to trigger a layout pass this.translationY = translationY;
if (getClass().getName().equals("androidx.coordinatorlayout.widget.CoordinatorLayout")) if (parent instanceof View)
native_queueAllocate(widget); ((View)parent).native_queueAllocate(((View)parent).widget);
} }
public void setX(float x) { public void setX(float x) {
@@ -2159,8 +2173,6 @@ public class View implements Drawable.Callback {
public int getTextAlignment() {return 0;} public int getTextAlignment() {return 0;}
public float getY() {return 0.f;}
public View findViewWithTag(Object tag) { public View findViewWithTag(Object tag) {
if (Objects.equals(tag, this.tag)) if (Objects.equals(tag, this.tag))
return this; return this;
@@ -2254,7 +2266,12 @@ public class View implements Drawable.Callback {
public boolean isDirty() { return false; } public boolean isDirty() { return false; }
public float getX() { return getLeft(); } public float getX() {
return getLeft() + getTranslationX();
}
public float getY() {
return getTop() + getTranslationY();
}
public boolean getGlobalVisibleRect(Rect visibleRect, Point globalOffset) { public boolean getGlobalVisibleRect(Rect visibleRect, Point globalOffset) {
boolean result = native_getGlobalVisibleRect(widget, visibleRect); boolean result = native_getGlobalVisibleRect(widget, visibleRect);