Search code examples
androidderived-classviewgroup

Can we set RelativeLayout or LinearLayout logic in ViewGroup derived class?


I have an abstract class ClassA which derives from ViewGroup.

I would like to extend ClassA to these class :

ClassB with LinearLayout layout logic

ClassC with RelativeLayout layout logic

Is this possible ?

I didn't found how to implement default LinearLayout or RelativeLayout logic in derived method onLayout() and onMeasure().

Is there any other solution if it's not possible ?


Solution

  • I think it would be better to extend LinearLayout and RelativeLayout directly from ClassB and ClassC. Then, you use composition to enhance those classes' behavior with the ClassA's logic.