You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
setLayoutParams(): better match Androids behaviour
View.setGravity() specifies gravity of children, not of the view itself LayoutParams.weight > 0 should cause expansion of widget
This commit is contained in:
@@ -783,6 +783,7 @@ public class View extends Object {
|
||||
private Context context;
|
||||
private Map<Integer,Object> tags = new HashMap<>();
|
||||
private Object tag;
|
||||
int gravity = -1; // fallback gravity for layout childs
|
||||
|
||||
int measuredWidth = 0;
|
||||
int measuredHeight = 0;
|
||||
@@ -839,11 +840,11 @@ public class View extends Object {
|
||||
throw new NullPointerException("Layout parameters cannot be null");
|
||||
}
|
||||
|
||||
native_set_size_request(params.width, params.height);
|
||||
int gravity = params.gravity;
|
||||
if (gravity == -1 && parent != null)
|
||||
gravity = parent.gravity;
|
||||
|
||||
if (params.gravity != -1) {
|
||||
setGravity(params.gravity);
|
||||
}
|
||||
native_setLayoutParams(widget, params.width, params.height, gravity, params.weight);
|
||||
|
||||
layout_params = params;
|
||||
}
|
||||
@@ -861,7 +862,10 @@ public class View extends Object {
|
||||
return Context.this_application.getResources();
|
||||
}
|
||||
|
||||
public native void setGravity(int gravity);
|
||||
public void setGravity(int gravity) {
|
||||
this.gravity = gravity;
|
||||
}
|
||||
|
||||
public native void setOnTouchListener(OnTouchListener l);
|
||||
public native void setOnClickListener(OnClickListener l);
|
||||
public /*native*/ void setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener l) {}
|
||||
@@ -869,7 +873,7 @@ public class View extends Object {
|
||||
public native final int getHeight();
|
||||
|
||||
protected native long native_constructor(Context context, AttributeSet attrs); // will create a custom GtkWidget with a custom drawing function
|
||||
private native void native_set_size_request(int width, int height);
|
||||
public native void native_setLayoutParams(long widget, int width, int height, int gravity, float weight);
|
||||
protected native void native_destructor(long widget);
|
||||
protected native void native_measure(long widget, int widthMeasureSpec, int heightMeasureSpec);
|
||||
protected native void native_layout(long widget, int l, int t, int r, int b);
|
||||
|
||||
@@ -270,6 +270,18 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
|
||||
}
|
||||
|
||||
public void focusableViewAvailable(View v) {}
|
||||
|
||||
@Override
|
||||
public void setGravity(int gravity) {
|
||||
super.setGravity(gravity);
|
||||
// update children as necessary
|
||||
for (View child: children) {
|
||||
LayoutParams params = child.getLayoutParams();
|
||||
if (params.gravity == -1)
|
||||
child.setLayoutParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LayoutParams {
|
||||
public static final int FILL_PARENT = -1;
|
||||
public static final int MATCH_PARENT = -1;
|
||||
@@ -277,7 +289,7 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
|
||||
|
||||
public int width = 0;
|
||||
public int height = 0;
|
||||
public float weight = 1;
|
||||
public float weight = 0;
|
||||
public int gravity = -1;
|
||||
|
||||
public LayoutParams() {
|
||||
|
||||
Reference in New Issue
Block a user