Looking at the documentation for android.widget.ScrollView and android.widget.HorizontalScrollView, both of them seem to implement
void addView(View child, int index)
So you would not have to change that line of code, if I am not missing anything here. Also, both classes inherit this method from android.view.ViewGroup. So, if the implementation of both classes is the same, you could do something like this
public abstract class ScrollViewDelegate<T extends FrameLayout> {
private final T view;
private LinearLayout L;
private AbsoluteLayout A;
public ScrollViewWrapper(T view) {
this.view = view;
L = new LinearLayout(view.getContext()); // or pass as parameter
A = new AbsoluteLayout(view.getContext()); // or pass as parameter
}
void update_scroll() {
view.removeView(L);
view.addView(L, 0);
L.removeView(A);
L.addView(A);
A.invalidate();
L.invalidate();
view.invalidate();
view.requestLayout();
}
// ...
}
and in HSV/VSV you can delegate to this class (if necessary).
public class HSV extends HorizontalScrollView {
private final ScrollViewDelegate<HorizontalScrollView> delegate;
public HSV(Context context) {
super(context);
this.delegate = new ScrollViewDelegate<HorizontalScrollView>(this);
}
// do stuff with this.delegate
}
public class VSV extends ScrollView {
private final ScrollViewDelegate<ScrollView> delegate;
public VSV(Context context) {
super(context);
this.delegate = new ScrollViewDelegate<ScrollView>(this);
}
}