Preview layout with merge root tag in Intellij IDEA/Android Studio

前端 未结 3 1958
小鲜肉
小鲜肉 2021-01-29 21:26

Let\'s imagine we are developing compound component based on LinearLayout. So, we create class like this:

public class SomeView extends LinearLayout {
    public         


        
3条回答
  •  遥遥无期
    2021-01-29 21:47

    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.

提交回复
热议问题