字体选择 自定义view+1
This commit is contained in:
parent
70e3aa1290
commit
35481519c5
|
|
@ -14,12 +14,12 @@ class FontSetView @JvmOverloads constructor(
|
||||||
) : LinearLayout(context, attrs, defStyleAttr) {
|
) : LinearLayout(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private var GAP = 1
|
private var GAP = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
private var mBinding: LayoutFontSetViewBinding
|
private var mBinding: LayoutFontSetViewBinding
|
||||||
|
|
||||||
private var mFontValue = 20
|
private var mFontValue = 16 // 12, 14, 16, 18, 20
|
||||||
|
|
||||||
init {
|
init {
|
||||||
mBinding = LayoutFontSetViewBinding.inflate(LayoutInflater.from(context), this, true)
|
mBinding = LayoutFontSetViewBinding.inflate(LayoutInflater.from(context), this, true)
|
||||||
|
|
@ -34,13 +34,35 @@ class FontSetView @JvmOverloads constructor(
|
||||||
ivFontPlus.setOnClickListener {
|
ivFontPlus.setOnClickListener {
|
||||||
mFontValue -= GAP
|
mFontValue -= GAP
|
||||||
tvFontValue.text = mFontValue.toString()
|
tvFontValue.text = mFontValue.toString()
|
||||||
|
levelSeekbar.setLevel((mFontValue - 16)/GAP)
|
||||||
}
|
}
|
||||||
|
|
||||||
ivFontAdd.setOnClickListener {
|
ivFontAdd.setOnClickListener {
|
||||||
mFontValue += GAP
|
mFontValue += GAP
|
||||||
tvFontValue.text = mFontValue.toString()
|
tvFontValue.text = mFontValue.toString()
|
||||||
|
levelSeekbar.setLevel((mFontValue - 16)/GAP)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
levelSeekbar.setOnLevelChangeListener(object : LevelSeekBar.OnLevelChangeListener {
|
||||||
|
override fun onLevelChanged(
|
||||||
|
seekBar: LevelSeekBar,
|
||||||
|
level: Int,
|
||||||
|
fromUser: Boolean
|
||||||
|
) {
|
||||||
|
mFontValue = 16 + level * GAP
|
||||||
|
tvFontValue.text = mFontValue.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStartTrackingTouch(seekBar: LevelSeekBar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStopTrackingTouch(seekBar: LevelSeekBar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ class LevelSeekBar @JvmOverloads constructor(
|
||||||
val trackBottom = centerY + trackHeight / 2
|
val trackBottom = centerY + trackHeight / 2
|
||||||
|
|
||||||
trackPaint.color = trackColor
|
trackPaint.color = trackColor
|
||||||
val trackRect = RectF(0f + nodeWidth/2, trackTop, width.toFloat(), trackBottom - nodeWidth/2)
|
val trackRect = RectF(0f + thumbRadius/2 + 6, trackTop, width.toFloat() - thumbRadius/2, trackBottom - nodeWidth/2 - 6)
|
||||||
canvas.drawRoundRect(trackRect, trackEndRadius, trackEndRadius, trackPaint)
|
canvas.drawRoundRect(trackRect, trackEndRadius, trackEndRadius, trackPaint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,7 +129,7 @@ class LevelSeekBar @JvmOverloads constructor(
|
||||||
|
|
||||||
nodePaint.color = if (i <= currentLevel) activeNodeColor else nodeColor
|
nodePaint.color = if (i <= currentLevel) activeNodeColor else nodeColor
|
||||||
//canvas.drawCircle(x, centerY, nodeRadius, nodePaint)
|
//canvas.drawCircle(x, centerY, nodeRadius, nodePaint)
|
||||||
val trackRect = RectF(x - thumbRadius/2, centerY - nodeHeight/2 + 6, x + thumbRadius/2, centerY + nodeHeight/2)
|
val trackRect = RectF(x - nodeWidth/2, centerY - nodeHeight/2 + 6, x + nodeWidth/2, centerY + nodeHeight/2)
|
||||||
canvas.drawRoundRect(trackRect, trackEndRadius, trackEndRadius, nodePaint)
|
canvas.drawRoundRect(trackRect, trackEndRadius, trackEndRadius, nodePaint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@
|
||||||
|
|
||||||
|
|
||||||
<com.remax.visualnovel.ui.chat.ui.LevelSeekBar
|
<com.remax.visualnovel.ui.chat.ui.LevelSeekBar
|
||||||
|
android:id="@+id/level_seekbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/dp_20"
|
android:layout_height="@dimen/dp_20"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue