I have the following class:
public final class ViewUtils {
public static void setSize(View view, int width, int height) {
ViewGroup.LayoutParams layoutParams = (ViewGroup.LayoutParams) view.getLayoutParams();
layoutParams.width = width;
layoutParams.height = height;
view.requestLayout();
}
public static void setWidth(View view, int width) {
setSize(view, width, view.getHeight());
}
public static void setHeight(View view, int height) {
setSize(view, view.getWidth(), height);
}
public static boolean isRightEdgeOfScrollViewHasBeenReached(HorizontalScrollView scrollView) {
View childView = scrollView.getChildAt(scrollView.getChildCount() - 1);
return childView.getRight() == (scrollView.getWidth() + scrollView.getScrollX());
}
// Other methods will be added later
}
But I don't like the name isRightEdgeOfScrollViewHasBeenReached. I think it would be better if the method name didn't contain word ScrollView but is placed in a class which would be specialized only on the ScrollView.
Should I place this method in an inner class ViewUtils.ScrollView or in a separate class ScrollViewUtils?
I think the first option would be better, because creating a separate class for a few methods (currently only one method) is too "expensive".
And help me choose more appropriate name for the method isRightEdgeOfScrollViewHasBeenReached.
Summarizing the question
The choice is between two options:
To have all methods inside a single class:
public class ViewUtils {
public static void methodForAllViews1() { }
public static void methodForAllViews2() { }
public static void methodForAllViews3() { }
public static class TextView {
public static void methodForTextViews1() { }
public static void methodForTextViews2() { }
}
// etc.
}
To separate all methods and to place all util classes in the same package:
- utils
- view
* ViewUtils.java
* TextViewUtils.java
* ScrollViewUtils.java