Let\'s imagine we are developing compound component based on LinearLayout. So, we create class like this:
public class SomeView extends LinearLayout {
public
Is also possible use custom class as parent instead of merge like
...
And then directly inflate this layout and cast result view to SomeView
.
Android studio will directly check parent class of SomeView
and handle preview like LinerLayout
.
You can use onFinishInflate()
method in the SomeView
to bind views by findViewById()
.
Benefit of this solution is that you can put all layout definitions or style definition directly to the layout file, you can't use method like setOrientation()
in code.