Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support mark below bar #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion RangeSeekBar/src/main/java/com/jaygoo/widget/RangeSeekBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public class RangeSeekBar extends View {
// the progress width
private int lineWidth;
protected int lineTop, lineBottom, lineLeft, lineRight;
private int textTop;
private boolean textBelow;
private int linePaddingRight;
private float touchDownX;
private float cellsPercent;
Expand Down Expand Up @@ -136,6 +138,11 @@ private void initProgressLine() {
if (progressRadius < 0){
progressRadius = (int) ((getLineBottom() - getLineTop()) * 0.45f);
}
if(textBelow){
textTop=(int)(lineTop+leftSB.getThumbSize() * leftSB.getThumbScaleRatio() / 2 + progressHeight / 2 + tickMarkTextMargin);
}else{
textTop=lineTop-tickMarkTextMargin;
}
}

private void initAttrs(AttributeSet attrs) {
Expand All @@ -156,6 +163,7 @@ private void initAttrs(AttributeSet attrs) {
tickMarkTextSize = (int) t.getDimension(R.styleable.RangeSeekBar_rsb_tick_mark_text_size, Utils.dp2px(getContext(),12));
tickMarkTextColor = t.getColor(R.styleable.RangeSeekBar_rsb_tick_mark_text_color, progressDefaultColor);
tickMarkInRangeTextColor = t.getColor(R.styleable.RangeSeekBar_rsb_tick_mark_text_color, progressColor);
textBelow=t.getBoolean(R.styleable.RangeSeekBar_rsb_text_below,false);
t.recycle();
}

Expand Down Expand Up @@ -231,7 +239,7 @@ protected void onDraw(Canvas canvas) {
x = getLineLeft() + lineWidth * (num - minProgress) / (maxProgress - minProgress)
- paint.measureText(text2Draw) / 2;
}
float y = getLineTop() - tickMarkTextMargin;
float y = textTop;
canvas.drawText(text2Draw, x, y, paint);
}
}
Expand Down
1 change: 1 addition & 0 deletions RangeSeekBar/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<attr name="rsb_thumb_inactivated_drawable" format="reference"/>
<attr name="rsb_thumb_size" format="dimension"/>
<attr name="rsb_thumb_scale_ratio" format="float"/>
<attr name="rsb_text_below" format="boolean"/>
</declare-styleable>

</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
app:rsb_indicator_margin="3dp"
app:rsb_thumb_scale_ratio="1.5"
app:rsb_thumb_drawable="@drawable/thumb_gradient"
/>
app:rsb_text_below="true"/>
<com.jaygoo.widget.RangeSeekBar
android:id="@+id/seekbar4"
android:layout_width="match_parent"
Expand Down