Ich landete meine eigene Sicht. Es sieht wie folgt aus -
public class TimerView extends View {
private static final String TAG = TimerView.class.getName();
private static final int RADIUS = 600;
private static final int BACKGROUND_COLOR = 0x50ff0000;
private static final int FOREGROUND_COLOR = 0xa0ff0000;
private static final float STARTING_ANGLE = -90f;
private static final float FULL_CIRCLE = 360f;
private ShapeDrawable circle;
private ShapeDrawable arc;
private float lastFraction;
public TimerView(Context context) {
super(context);
this.init();
}
public TimerView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
this.init();
}
private void init() {
this.circle = new ShapeDrawable(new OvalShape());
this.circle.getPaint().setColor(BACKGROUND_COLOR);
this.circle.setBounds(0, 0, RADIUS, RADIUS);
this.lastFraction = 0f;
this.arc = new ShapeDrawable(new ArcShape(STARTING_ANGLE,
this.lastFraction));
this.arc.getPaint().setColor(FOREGROUND_COLOR);
this.arc.setBounds(0, 0, RADIUS, RADIUS);
}
protected void onDraw(Canvas canvas) {
this.circle.draw(canvas);
this.arc.draw(canvas);
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.setMeasuredDimension(RADIUS, RADIUS);
}
public void setFraction(float fraction) {
if (fraction < 0f || fraction > 1.f) {
throw new IllegalArgumentException("Out of range: " + fraction);
}
if (fraction != this.lastFraction) {
float sweepingAngle = FULL_CIRCLE * fraction;
this.arc.setShape(new ArcShape(STARTING_ANGLE, sweepingAngle));
this.postInvalidate();
this.lastFraction = fraction;
} else {
Log.v(TAG, "Error");
}
}
}
Und im Layout Aufruf -
<com.abc.xyz.TimerView
android:id="@+id/pieChart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp" />
Um den Wert zu ändern für die Aktivität oder das Fragment anrufen müssen -
pieChart.setFraction((float) .99);
Vielen Dank für jedermann ist so viel Unterstützung
Ich sagte, brauche nur einen Vorschlag, ich frage nicht nach Lösung Ich a Wir haben schon die Analoguhr gemacht. Warum seid ihr unten abgestimmt? – Anirban