1、自定義Viewandroid
一、構造方法的選中,獲取一些須要用到的值app
二、重寫onMeasure方法,計算子View的寬高,以及本身的寬高佈局
三、重寫onLayout方法,決定子View的佈局位置this
四、須要用的手勢是可重寫onTouchEvent方法xml
2、構造方法test
一、一個參數的構造方法方法
context new CustomSidingView(context)項目
二、兩個參數的構造方法
di
Context context, AttributeSet attrs(佈局文件中申明的屬性,在沒有自定義屬性的狀況下) CustomSidingView(Context context, AttributeSet attrs)文件
三、三個參數的構造方法
Context context, AttributeSet attrs, int defStyle(有自定義屬性時並用自定義屬性時調用)
CustomSidingView(Context context, AttributeSet attrs, int defStyle)
在自定義屬性的時候通常三個構造方法都會用
在一個參數的構造方法調用 this(context, null);
在兩個參數的構造方法中調用 this(context, attrs, 0);
在三個參數的構造方法中調用 super(context, attrs, defStyle);
3、自定義屬性
一、在attrs.xml 文件中自定義
二、在佈局文件中使用自定義屬性(注意:在佈局文件中必定要申明 xmlns 如:app="http://schemas.android.com/apk/res/com.test.sildingmenu"(其中「app」隨便定義,「http://schemas.android.com/apk/res/」爲固定格式,「com.test.sildingmenu」爲項目包名))
三、在三個參數的構造方法裏面得到自定義屬性的值