Comments (1)
Here is my solution for your reference. FYI.
1. Declare a global variable.
private int minSize = 0;
2. Create a method to calculate the height of the arc.
private int getArcHeight(int min) {
int angle = 180 - mSweepAngle / 2;
double arc = Math.PI * 2 / 360 * (angle);
int arcHeight = (int) ((Math.cos(arc) + 1) * (min / 2));
return arcHeight;
}
3. Override onMeasure() and give a min height.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = getDefaultSize(getSuggestedMinimumHeight(),
heightMeasureSpec);
final int width = getDefaultSize(getSuggestedMinimumWidth(),
widthMeasureSpec);
final int min = Math.min(width, height);
float top = 0;
float left = 0;
float right = 0;
float bottom = 0;
int arcDiameter = 0;
minSize = min;
arcDiameter = min - getPaddingLeft();
mTranslateX = (int) (width * 0.5f);
mTranslateY = (int) (min * 0.5f);
mArcRadius = arcDiameter / 2;
top = min / 2 - (arcDiameter / 2);
left = width / 2 - (arcDiameter / 2);
right = (left + arcDiameter);
bottom = (top + arcDiameter);
mArcRect.set(left, top, right, bottom);
int newHeight = (int) (getArcHeight(minSize) + top);
int arcStart = (int) mProgressSweep + mStartAngle + mRotation + 90;
mThumbXPos = (int) (mArcRadius * Math.cos(Math.toRadians(arcStart)));
mThumbYPos = (int) (mArcRadius * Math.sin(Math.toRadians(arcStart)));
setTouchInSide(mTouchInside);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// Set view height
setMeasuredDimension(width, newHeight);
}
4. Override onDraw() and adjust canvas size.
@Override
protected void onDraw(Canvas canvas) {
if (!mClockwise) {
canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY());
}
// Draw the arcs
final int arcStart = mStartAngle + mAngleOffset + mRotation;
final int arcSweep = mSweepAngle;
// Erase the area 2
double newHeight = getArcHeight(minSize) + getPaddingLeft() / 2;
canvas.clipRect(0, 0, getMeasuredWidth(), (int) (newHeight), Region.Op.INTERSECT);
// Set a conspicuous background, just for test.
canvas.drawColor(Color.RED);
canvas.drawArc(mArcRect, arcStart, arcSweep, false, mArcPaint);
canvas.drawArc(mArcRect, arcStart, mProgressSweep, false,
mProgressPaint);
if (mEnabled) {
// Draw the thumb nail
canvas.translate(mTranslateX - mThumbXPos, mTranslateY - mThumbYPos);
mThumb.draw(canvas);
}
}
This is a demo screenshot.
from seekarc.
Related Issues (20)
- Progress color cannot be changed programatically
- Locking the SeekArc when 360 is reached, instead of starting from 0 HOT 6
- Any plan to port to Xamarin? HOT 1
- Progress width is not changing
- setMin and getMin in not available. HOT 1
- Slow response on animating slider / Lag on calling it inside fragment HOT 1
- How do I add left and right arcs to make a circle?
- How do I add two semi arc with left and right to make a circle?
- Provide code in objective c HOT 1
- Enable Disable SeekArc from different threads doesn't work
- Gradient coloring for seek arc HOT 1
- Cannot easily drag to min or max
- Unable set max value programatically HOT 2
- Using Readme example not showing HOT 1
- Manifest error while building project HOT 4
- how to change seekArc thumb or thumb color? HOT 1
- duplicate value for resource
- Namespace 'seekarc' is not bound.
- updating progress and arc colors programmatically HOT 1
- Gradle build Failing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from seekarc.