gpt4 book ai didi

android - android中的馅饼进度条

转载 作者:行者123 更新时间:2023-12-03 23:23:29 25 4
gpt4 key购买 nike

嗨,我想在 android 中制作一个 Pie 进度条,就像所附图像一样。

enter image description here

我已经完成了以下代码,但没有任何收获。 enter link description here

所以我决定编写自己的 ProgressBarView。这是我的示例代码..

public class PieProgressView extends View {

private float mProgress;

private int MAX_ANGLE = 360;


public PieProgressView(Context context) {
super(context);
}

public PieProgressView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public PieProgressView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}



@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
drawOval(canvas);

}

public void setProgress(int progress){
mProgress = (float) ((float)progress*3.6);
invalidate();
}

private void drawOval(Canvas canvas){
canvas.drawColor(Color.CYAN);
Paint paint = new Paint();
// smooths
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.RED);
RectF oval2 = new RectF(50, 50, 500, 500);
canvas.drawOval(oval2, paint);// opacity

Paint p = new Paint();
p.setColor(Color.BLACK);
canvas.drawArc(oval2, 270, mProgress, true, p);
System.out.println("drawOval Progress == "+mProgress);


//p.setAlpha(0x80); //
}

}

和我称之为的 Activity 课..
 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

button = (Button)findViewById(R.id.button);
pieProgressView = (PieProgressView)findViewById(R.id.pieprogress);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fillProgress();
}
});

}

private void fillProgress(){
for(int i=0;i<100 ; i++) {

pieProgressView.setProgress(i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();

}
}
}

现在在这个 for 循环期间没有显示任何进度,但是在 for 循环完成后,它会显示进度条,如附图所示,显示黑色进度。

谁能告诉我这段代码有什么问题。为什么这段代码不做持续更新?

最佳答案

我实现它就像

<ProgressBar
android:id="@+id/pr_progress_in_circle"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="24dp"
android:layout_height="24dp"
android:indeterminate="false"
android:max="100"
android:progress="60"
android:progressDrawable="@drawable/progress"
android:rotation="-90" />

哪里progress.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">


<item
android:bottom="@dimen/dimen_2"
android:left="@dimen/dimen_2"
android:right="@dimen/dimen_2"
android:top="@dimen/dimen_2">
<shape android:shape="oval">
<solid android:color="@color/grey_lighter" />
<stroke android:color="@android:color/transparent" />
</shape>
</item>
<item>
<shape
android:innerRadiusRatio="100"
android:shape="ring"
android:thicknessRatio="2.5"
android:useLevel="true">
<gradient
android:centerColor="@color/orange_above_avg"
android:endColor="@color/orange_above_avg"
android:startColor="@color/orange_above_avg"
android:type="sweep"
android:useLevel="false" />
</shape>
</item>


</layer-list>

你可以通过
        mProgressBar.setMax(totalQuestions);
mProgressBar.setProgress(correctQuestion);

enter image description here

或前往 this library

关于android - android中的馅饼进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34893124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com