ScrollView: implement custom onMeasure()

This commit is contained in:
Julian Winkler
2024-03-11 18:23:38 +01:00
parent 9fbfe9dea1
commit c0bc875c11
3 changed files with 20 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ JNIEXPORT jlong JNICALL Java_android_widget_ScrollView_native_1constructor(JNIEn
GtkWidget *scrolled_window = gtk_scrolled_window_new();
wrapper_widget_set_child(WRAPPER_WIDGET(wrapper), scrolled_window);
gtk_widget_set_name(scrolled_window, "ScrollView");
(*env)->SetBooleanField(env, this, _FIELD_ID(_CLASS(this), "haveCustomMeasure", "Z"), true);
return _INTPTR(scrolled_window);
}

View File

@@ -1632,4 +1632,6 @@ public class View extends Object {
public boolean getGlobalVisibleRect(Rect visibleRect) {
return native_getGlobalVisibleRect(widget, visibleRect);
}
public boolean onCheckIsTextEditor() {return false;}
}

View File

@@ -2,6 +2,7 @@ package android.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
public class ScrollView extends ViewGroup {
@@ -20,5 +21,21 @@ public class ScrollView extends ViewGroup {
@Override
protected native void native_removeView(long widget, long child);
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = 0;
int height = 0;
if (getChildCount() > 0) {
View child = getChildAt(0);
LayoutParams lp = child.getLayoutParams();
int childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, lp.width);
int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
width = child.getMeasuredWidth();
height = child.getMeasuredHeight();
}
setMeasuredDimension(resolveSize(width, widthMeasureSpec), resolveSize(height, heightMeasureSpec));
}
public void setFillViewport(boolean fillViewport) {}
}