自定義View不同構造的含義

public TickView(Context context) {
        this(context, null);
    }

    public TickView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TickView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

一個參數的構造方法,用於直接在Java代碼中實例化控件;
兩個參數的構造方法,用於在xml中使用,通過findviewById或者inflate的方式實例化。
三個參數的構造方法,用於在xml中使用,並且設置了style的情況下。



作者:jiting45
鏈接:https://www.jianshu.com/p/fa57cb09620d
來源:簡書
著作權歸作者所有。商業轉載請聯繫作者獲得授權,非商業轉載請註明出處。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章