version:beta
fix: update:seekbar增加刻度
This commit is contained in:
@@ -8,6 +8,7 @@ import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
||||
public class RulerSeekBar extends androidx.appcompat.widget.AppCompatSeekBar {
|
||||
|
||||
@@ -29,13 +30,15 @@ public class RulerSeekBar extends androidx.appcompat.widget.AppCompatSeekBar {
|
||||
/**
|
||||
* 刻度线的颜色
|
||||
*/
|
||||
private int mRulerColor = Color.WHITE;
|
||||
private int mRulerColor = Color.GRAY;
|
||||
|
||||
/**
|
||||
* 滑块上面是否要显示刻度线
|
||||
*/
|
||||
private boolean isShowTopOfThumb = true;
|
||||
|
||||
private int radius = 8;
|
||||
|
||||
public RulerSeekBar(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
@@ -80,23 +83,46 @@ public class RulerSeekBar extends androidx.appcompat.widget.AppCompatSeekBar {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int thumbRadius = 0;
|
||||
if (getThumb() != null) {
|
||||
Rect rect = getThumb().getBounds();
|
||||
thumbRadius = (rect.right - rect.left) / 2;
|
||||
}
|
||||
Log.e("RulerSeekBar", "onDraw: thumbRadius = " + thumbRadius);
|
||||
|
||||
|
||||
//获取每一份的长度
|
||||
int length = (getWidth() - getPaddingLeft() - getPaddingRight() - mRulerCount * mRulerWidth) / (mRulerCount + 1);
|
||||
int length = (getWidth() - getPaddingLeft() - getPaddingRight() - (mRulerCount + 1) * (radius) - thumbRadius * 2) / (mRulerCount + 1);
|
||||
Log.e("RulerSeekBar", "onDraw: mRulerCount = " + mRulerCount);
|
||||
|
||||
Log.e("RulerSeekBar", "onDraw: getWidth = " + getWidth());
|
||||
Log.e("RulerSeekBar", "onDraw: getPaddingLeft = " + getPaddingLeft());
|
||||
Log.e("RulerSeekBar", "onDraw: getPaddingRight = " + getPaddingRight());
|
||||
Log.e("RulerSeekBar", "onDraw: length = " + length);
|
||||
|
||||
//计算刻度线的顶部坐标和底部坐标
|
||||
Log.e("RulerSeekBar", "onDraw: getHeight = " + getHeight());
|
||||
Log.e("RulerSeekBar", "onDraw: getMinimumHeight = " + getMinimumHeight());
|
||||
|
||||
int rulerTop = getHeight() / 2 - getMinimumHeight() / 2;
|
||||
int rulerBottom = rulerTop + getMinimumHeight();
|
||||
Log.e("RulerSeekBar", "onDraw: rulerTop = " + rulerTop);
|
||||
Log.e("RulerSeekBar", "onDraw: rulerBottom = " + rulerBottom);
|
||||
int center = getHeight() / 2;
|
||||
|
||||
//获取滑块的位置信息
|
||||
Rect thumbRect = null;
|
||||
if (getThumb() != null) {
|
||||
thumbRect = getThumb().getBounds();
|
||||
}
|
||||
Log.e("RulerSeekBar", "onDraw: thumbRect = " + thumbRect);
|
||||
|
||||
//绘制刻度线
|
||||
for (int i = 1; i <= mRulerCount; i++) {
|
||||
for (int i = 0; i <= mRulerCount + 1; i++) {
|
||||
//计算刻度线的左边坐标和右边坐标
|
||||
int rulerLeft = i * length + getPaddingLeft();
|
||||
Log.e("RulerSeekBar", "onDraw: rulerLeft = " + rulerLeft);
|
||||
int rulerRight = rulerLeft + mRulerWidth;
|
||||
|
||||
//判断是否需要绘制刻度线
|
||||
@@ -104,9 +130,13 @@ public class RulerSeekBar extends androidx.appcompat.widget.AppCompatSeekBar {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (rulerLeft > thumbRect.left && rulerLeft < thumbRect.right) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//进行绘制
|
||||
// canvas.drawRect(rulerLeft, rulerTop, rulerRight, rulerBottom, mRulerPaint);
|
||||
canvas.drawCircle(rulerLeft, rulerTop, 12, mRulerPaint);
|
||||
canvas.drawCircle(rulerLeft + radius + thumbRadius, center, radius, mRulerPaint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
<item android:id="@android:id/background">
|
||||
<shape>
|
||||
<solid android:color="#e1e8f0" />
|
||||
<size android:height="8dp" />
|
||||
<corners android:radius="8dp" />
|
||||
<size android:height="@dimen/dp_14" />
|
||||
<corners android:radius="@dimen/dp_14" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
android:centerColor="#e1e8f0"
|
||||
android:endColor="#e1e8f0"
|
||||
android:startColor="#e1e8f0" />
|
||||
<size android:height="8dp" />
|
||||
<corners android:radius="8dp" />
|
||||
<size android:height="@dimen/dp_14" />
|
||||
<corners android:radius="@dimen/dp_14" />
|
||||
</shape>
|
||||
</clip>
|
||||
</item>
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
android:shape="oval">
|
||||
|
||||
<size
|
||||
android:width="15dp"
|
||||
android:height="15dp" />
|
||||
android:width="@dimen/dp_14"
|
||||
android:height="@dimen/dp_14" />
|
||||
|
||||
<solid android:color="@android:color/holo_blue_light" />
|
||||
</shape>
|
||||
@@ -154,6 +154,54 @@
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_margin="@dimen/dp_8"
|
||||
android:layout_weight="1">
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekbar_sound"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@null"
|
||||
android:paddingStart="0dp"
|
||||
android:paddingEnd="0dp"
|
||||
android:progressDrawable="@drawable/seekbar_progress_default"
|
||||
android:thumb="@null"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_sound"
|
||||
android:layout_width="@dimen/dp_36"
|
||||
android:layout_height="@dimen/dp_36"
|
||||
android:layout_marginStart="@dimen/dp_8"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/sound1"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_sound"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_16"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"
|
||||
android:text="100%"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/sp_24"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/iv_sound"
|
||||
app:layout_constraintStart_toEndOf="@+id/iv_sound"
|
||||
app:layout_constraintTop_toTopOf="@+id/iv_sound" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
@@ -169,8 +217,8 @@
|
||||
android:layout_marginStart="@dimen/dp_20"
|
||||
android:layout_marginEnd="@dimen/dp_20"
|
||||
android:max="3"
|
||||
android:maxHeight="12dp"
|
||||
android:minHeight="12dp"
|
||||
android:maxHeight="@dimen/dp_14"
|
||||
android:minHeight="@dimen/dp_14"
|
||||
android:progress="0"
|
||||
android:progressDrawable="@drawable/shape_progress_drawable"
|
||||
android:thumb="@drawable/shape_thumb_icon"
|
||||
@@ -252,53 +300,6 @@
|
||||
<!-- app:layout_constraintTop_toBottomOf="@+id/tv_font_size" />-->
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_margin="@dimen/dp_8"
|
||||
android:layout_weight="1">
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekbar_sound"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@null"
|
||||
android:paddingStart="0dp"
|
||||
android:paddingEnd="0dp"
|
||||
android:progressDrawable="@drawable/seekbar_progress_default"
|
||||
android:thumb="@null"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_sound"
|
||||
android:layout_width="@dimen/dp_36"
|
||||
android:layout_height="@dimen/dp_36"
|
||||
android:layout_marginStart="@dimen/dp_8"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/sound1"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_sound"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_16"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"
|
||||
android:text="100%"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/sp_24"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/iv_sound"
|
||||
app:layout_constraintStart_toEndOf="@+id/iv_sound"
|
||||
app:layout_constraintTop_toTopOf="@+id/iv_sound" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
||||
@@ -256,8 +256,8 @@
|
||||
android:layout_marginStart="@dimen/dp_32"
|
||||
android:layout_marginEnd="@dimen/dp_32"
|
||||
android:max="3"
|
||||
android:maxHeight="12dp"
|
||||
android:minHeight="12dp"
|
||||
android:maxHeight="@dimen/dp_14"
|
||||
android:minHeight="@dimen/dp_14"
|
||||
android:progress="0"
|
||||
android:progressDrawable="@drawable/shape_progress_drawable"
|
||||
android:thumb="@drawable/shape_thumb_icon"
|
||||
|
||||
Reference in New Issue
Block a user