Sobes.tech
Junior — Middle

Which base class should be inherited when creating your own Layout component in the View system?

sobes.tech AI

Answer from AI

When creating a custom Layout component in Android, it is usually inherited from the ViewGroup class. This class serves as the base for all containers that can hold other Views and manage their layout.

For example:

public class CustomLayout extends ViewGroup {
    public CustomLayout(Context context) {
        super(context);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        // Implement the layout logic for child elements here
    }
}

Thus, inheriting from ViewGroup allows creating custom layouts with specific behavior for positioning child elements.