美文网首页
鸿蒙学习-ProgressBar,RoundProgressBa

鸿蒙学习-ProgressBar,RoundProgressBa

作者: 学渣中的战斗渣 | 来源:发表于2021-04-12 14:07 被阅读0次

    ProgressBar进度条控件,用于显示内容或操作的进度。

    常用方法

    ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_pb);

    //设置最大值

            progressBar.setMaxValue(100);

    //设置最小值

            progressBar.setMinValue(0);

    //设置当前进度

            progressBar.setProgressValue(25);

    //设置当前父进度

            progressBar.setViceProgress(50);

    //设置提示文字的大小

            progressBar.setProgressHintTextSize(50);

    //设置提示文字的位置,通过TextAlignment设置,可设置多个

    progressBar.setProgressHintTextAlignment(TextAlignment.TOP|TextAlignment.HORIZONTAL_CENTER);

    //设置提示文字的颜色

            progressBar.setProgressHintTextColor(Color.RED);

    //设置提示文字

            progressBar.setProgressHintText(progressBar.getProgress()+"%");

            ShapeElement element=new ShapeElement();

            element.setRgbColor(new RgbColor(18,52,86));

    //设置主进度条样式,传入一个Element

            progressBar.setProgressElement(element);

    //设置副进度条样式,传入一个Element

            progressBar.setViceProgressElement();

    //设置进度条背景样式,传入一个Element

    progressBar.setInfiniteModeElement();

    效果图:

    不确定模式:不知道当前进度,一直进行加载中动画

    infinite:是否使用不确定模式,传入boolean类型

    infinite_element:不确定模式图样,配置前提:infinite需设置为true,仅可引用media/graphic下的图片资源。

    RoundProgressBar继承自ProgressBar,用于显示环形进度。

    //设置最大角度

    progressBar.setMaxAngle(270);

    //设置开始角度

    progressBar.setStartAngle(45);

    代码示例

    //RoundProgressBar目前只支持使用代码的形式修改二级进度

    RoundProgressBar progressBar =new RoundProgressBar(this);

    progressBar.setProgressColor(Color.RED);

    progressBar.setWidth(200);

    progressBar.setHeight(200);

    ShapeElement element =new ShapeElement();

    element.setShape(ShapeElement.ARC);

    element.setRgbColor(RgbColor.fromArgbInt(Color.TRANSPARENT.getValue()));

    element.setStroke(progressBar.getProgressWidth(), RgbColor.fromArgbInt(Color.YELLOW.getValue()));

    progressBar.setViceProgressElement(element);

    ShapeElement grey =new ShapeElement();

    grey.setShape(ShapeElement.ARC);

    grey.setRgbColor(RgbColor.fromArgbInt(Color.TRANSPARENT.getValue()));

    grey.setStroke(progressBar.getProgressWidth(), RgbColor.fromArgbInt(Color.GRAY.getValue()));

    progressBar.setProgressBackgroundElement(grey);

    progressBar.setMaxValue(100);

    progressBar.setMinValue(0);

    progressBar.setProgressValue(50);

    progressBar.setViceProgress(75);

    效果图:

    相关文章

      网友评论

          本文标题:鸿蒙学习-ProgressBar,RoundProgressBa

          本文链接:https://www.haomeiwen.com/subject/ducukltx.html