private class HSV extends HorizontalScrollView {
public LinearLayout L;
public AbsoluteLayout A;
public HSV(Context context) {
super(context);
L = new LinearLayout(context);
A = new AbsoluteLayout(context);
}
@Override public void addView(View child) {
A.addView(child);
}
void update_scroll() {
removeView(L);
addView(L, 0);
L.removeView(A);
L.addView(A);
A.invalidate();
L.invalidate();
invalidate();
requestLayout();
}
int GetCurrentPos() {
return getScrollX();
return getScrollY();
}
... few more methods skipped, they will not change at all in 'vertical' version
}
I have this class, it does exactly what I want. Now I need a new VSV class that will be inferred from the (vertical) ScrollView and be the same. I can simply copy the entire block and change the HorizontalScrolView extends to expand the ScrollView , and then (L, 0) to (0, L) (oops, this was an error when publishing to SO, of course, this line will not change, GetCurrentPos will be).
or I can add the "bool vertical" property. But Java has no templates or macros or prototypes of the runtime environment, so is there any other way in Java to avoid code duplication in this example?