▼ 自定義View分類
● 自定義ViewGroup
自定義ViewGroup大多繼承自ViewGroup或各種Layout,包含有子View,一般是利用現有的組件根據特定的布局方式來組成新的組件。
● 自定義View
自定義View一般繼承自View,SurfaceView或其他的View,在沒有現成的View,需要自己實現的時候,就使用自定義View,不包含子View。
▼ 重寫的幾個方法
● 構造方法
構造函數是View的入口,可以用于初始化一些的內容,和獲取自定義屬性。
<pre>
public void SloopView(Context context) {}
public void SloopView(Context context, AttributeSet attrs) {}
public void SloopView(Context context, AttributeSet attrs, int defStyleAttr) {}
public void SloopView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {}
</pre>
以下方法調用的是一個參數的構造函數:
<pre>
//在Avtivity中
WuCircularStatistics view=new WuCircularStatistics(this);
</pre>
以下方法調用的是兩個參數的構造函數:
<pre>
//在layout文件中 - 格式為: 包名.View名
<com.nameWu.mainInfor.WuCircularStatistics
android:id="@+id/tab_data_circle"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</pre>
常用的就是一個參數,兩個參數的構造方法,三四個參數的構造方法以后用到了再進行更新...