修正分針、時針長度
This commit is contained in:
parent
0fe157ff87
commit
d9ac3caf85
@ -105,7 +105,7 @@ class IOSClockView: View {
|
||||
|
||||
drawScaleHourHand(canvas, 12)
|
||||
|
||||
postInvalidateDelayed(100)
|
||||
postInvalidateDelayed(30)
|
||||
}
|
||||
|
||||
private fun drawClockFace(canvas: Canvas?) {
|
||||
@ -157,10 +157,11 @@ class IOSClockView: View {
|
||||
val hour = calendar[Calendar.HOUR]
|
||||
val minute = calendar[Calendar.MINUTE]
|
||||
val second = calendar[Calendar.SECOND]
|
||||
val millisecond = calendar[Calendar.MILLISECOND]
|
||||
// 計算時、分、秒的旋轉角度
|
||||
val angleHour = (hour + minute.toFloat() / 60) * 360 / 12
|
||||
val angleMinute = (minute + second.toFloat() / 60) * 360 / 60
|
||||
val angleSecond = second * 360 / 60
|
||||
val angleSecond = ((second + (millisecond / 1000f)) * 360f / 60f)
|
||||
|
||||
//region 繪製時針
|
||||
canvas?.save()
|
||||
@ -168,27 +169,27 @@ class IOSClockView: View {
|
||||
canvas?.rotate(angleHour, centerX, centerY)
|
||||
// 繪製時針1
|
||||
val rectHour = RectF(
|
||||
centerX - 10f / 2,
|
||||
centerY - radius / 2,
|
||||
centerX + 10f / 2,
|
||||
centerX - (width * 0.02f) / 2,
|
||||
centerY - radius / 1.75f,
|
||||
centerX + (width * 0.02f) / 2,
|
||||
centerY - radius / 6
|
||||
)
|
||||
// 設定時針畫筆屬性
|
||||
mPaint.color = Color.BLACK
|
||||
mPaint.style = Paint.Style.STROKE
|
||||
mPaint.style = Paint.Style.FILL_AND_STROKE
|
||||
mPaint.strokeWidth = 10f
|
||||
canvas?.drawRoundRect(rectHour, mPointRange, mPointRange, mPaint)
|
||||
|
||||
// 繪製時針2
|
||||
val rectHour2 = RectF(
|
||||
centerX - 10f / 2,
|
||||
centerY - radius / 2,
|
||||
centerX + 10f / 2,
|
||||
centerX - (width * 0.01f) / 2,
|
||||
centerY - radius / 1.75f,
|
||||
centerX + (width * 0.01f) / 2,
|
||||
centerY
|
||||
)
|
||||
// 設定時針畫筆屬性
|
||||
mPaint.color = Color.BLACK
|
||||
mPaint.style = Paint.Style.FILL
|
||||
mPaint.style = Paint.Style.FILL_AND_STROKE
|
||||
mPaint.strokeWidth = 5f
|
||||
canvas?.drawRoundRect(rectHour2, mPointRange, mPointRange, mPaint)
|
||||
canvas?.restore()
|
||||
@ -200,26 +201,26 @@ class IOSClockView: View {
|
||||
// 旋轉到分針的角度
|
||||
canvas?.rotate(angleMinute, centerX, centerY)
|
||||
val rectMinute = RectF(
|
||||
centerX - 10f / 2,
|
||||
centerY - radius * 3.5f / 5,
|
||||
centerX + 10f / 2,
|
||||
centerX - (width * 0.02f) / 2,
|
||||
centerY - radius + 20f,
|
||||
centerX + (width * 0.02f) / 2,
|
||||
centerY - radius / 6
|
||||
)
|
||||
// 設定分針畫筆屬性
|
||||
mPaint.color = Color.BLACK
|
||||
mPaint.style = Paint.Style.STROKE
|
||||
mPaint.style = Paint.Style.FILL_AND_STROKE
|
||||
mPaint.strokeWidth = 10f
|
||||
canvas?.drawRoundRect(rectMinute, mPointRange, mPointRange, mPaint)
|
||||
|
||||
val rectMinute2 = RectF(
|
||||
centerX - 10f / 2,
|
||||
centerY - radius * 3.5f / 5,
|
||||
centerX + 10f / 2,
|
||||
centerX - (width * 0.01f) / 2,
|
||||
centerY - radius + 20f,
|
||||
centerX + (width * 0.01f) / 2,
|
||||
centerY
|
||||
)
|
||||
// 設定分針畫筆屬性
|
||||
mPaint.color = Color.BLACK
|
||||
mPaint.style = Paint.Style.FILL
|
||||
mPaint.style = Paint.Style.FILL_AND_STROKE
|
||||
mPaint.strokeWidth = 5f
|
||||
canvas?.drawRoundRect(rectMinute2, mPointRange, mPointRange, mPaint)
|
||||
canvas?.restore()
|
||||
@ -233,16 +234,16 @@ class IOSClockView: View {
|
||||
// 繪製秒針
|
||||
canvas?.save()
|
||||
// 旋轉到分針的角度
|
||||
canvas?.rotate(angleSecond.toFloat(), centerX, centerY)
|
||||
canvas?.rotate(angleSecond, centerX, centerY)
|
||||
val rectSecond = RectF(
|
||||
centerX - 5f / 2,
|
||||
centerX - (width * 0.005f) / 2,
|
||||
centerY - radius + 20,
|
||||
centerX + 5f / 2,
|
||||
centerX + (width * 0.005f) / 2,
|
||||
centerY + radius / 6
|
||||
)
|
||||
// 設定秒針畫筆屬性
|
||||
mPaint.strokeWidth = 5f
|
||||
mPaint.style = Paint.Style.STROKE
|
||||
mPaint.style = Paint.Style.FILL_AND_STROKE
|
||||
mPaint.color = Color.parseColor("#FF7F27")
|
||||
canvas?.drawRoundRect(rectSecond, mPointRange, mPointRange, mPaint)
|
||||
canvas?.restore()
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:width="15dp"
|
||||
android:height="150dp">
|
||||
android:height="200dp">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent" />
|
||||
<corners android:radius="10dp" />
|
||||
@ -9,7 +9,7 @@
|
||||
</item>
|
||||
<item
|
||||
android:width="5dp"
|
||||
android:height="75dp"
|
||||
android:height="100dp"
|
||||
android:top="0dp"
|
||||
android:left="5dp"
|
||||
android:right="5dp">
|
||||
@ -20,7 +20,7 @@
|
||||
</item>
|
||||
<item
|
||||
android:width="7.5dp"
|
||||
android:height="50dp"
|
||||
android:height="75dp"
|
||||
android:top="0dp"
|
||||
android:left="3.75dp"
|
||||
android:right="3.75dp">
|
||||
@ -32,7 +32,7 @@
|
||||
<item
|
||||
android:width="15dp"
|
||||
android:height="15dp"
|
||||
android:top="68dp">
|
||||
android:top="92.5dp">
|
||||
<shape android:shape="oval">
|
||||
<stroke android:color="@color/black" android:width="2dp" />
|
||||
<solid android:color="@color/black" />
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:width="15dp"
|
||||
android:height="250dp">
|
||||
android:height="295dp">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent" />
|
||||
<corners android:radius="10dp" />
|
||||
@ -9,7 +9,7 @@
|
||||
</item>
|
||||
<item
|
||||
android:width="5dp"
|
||||
android:height="125dp"
|
||||
android:height="147.5dp"
|
||||
android:top="0dp"
|
||||
android:left="5dp"
|
||||
android:right="5dp">
|
||||
@ -20,7 +20,7 @@
|
||||
</item>
|
||||
<item
|
||||
android:width="7.5dp"
|
||||
android:height="100dp"
|
||||
android:height="125dp"
|
||||
android:top="0dp"
|
||||
android:left="3.75dp"
|
||||
android:right="3.75dp">
|
||||
@ -32,7 +32,7 @@
|
||||
<item
|
||||
android:width="15dp"
|
||||
android:height="15dp"
|
||||
android:top="118dp">
|
||||
android:top="140dp">
|
||||
<shape android:shape="oval">
|
||||
<stroke android:color="@color/black" android:width="2dp" />
|
||||
<solid android:color="@color/black" />
|
||||
|
||||
Loading…
Reference in New Issue
Block a user