- mStrokeInset:
表示讓RectF向上下、左右的增加或減少量,arcBounds.inset(mStrokeInset, mStrokeInset);
,mStrokeInset>0是減小,mStrokeInset<0是放大,其值爲:
if (mRingCenterRadius <= 0 || minEdge < 0) {
insets = (float) Math.ceil(mStrokeWidth / 2.0f);
} else {
insets = (float) (minEdge / 2.0f - mRingCenterRadius);
}
mStrokeInset = insets;
- 圓的半徑以及畫筆的寬度
這個控件實際上是由圓環和三角形拼接起來的,那麼該怎麼移動三角形使之與圓環實現無縫結合就是關鍵了,先看一下當畫一個圓環時,它的起始角度爲0,偏移角度爲1的時候是什麼樣的,入下圖所示:
就是圖中紅線的位置,這就是起始位置,要想把畫好的三角形移動到這個位置,那麼該偏移多少呢,y軸很簡單,偏移內切矩形圓的半徑即可(bounds.exactCenterY()),那麼x軸呢?理論上來講是一個內切矩形圓的半徑+圓環的半徑是正確的,但是別忘了,這個矩形也做過放縮(arcBounds.inset(mStrokeInset, mStrokeInset)
),那麼我們在原來的基礎上再減去mStrokeInset/2就對了;另一個需要清楚的問題,如下圖所示:
假如紅色圓環表示的是畫筆的寬度,而那條灰色的線就表示圓環的半徑和畫筆寬度的關係。