【鸿蒙 HarmonyOS】UI 组件 ( 进度条 ProgressBar 和 RoundProgressBar 组件 )(二)

简介: 【鸿蒙 HarmonyOS】UI 组件 ( 进度条 ProgressBar 和 RoundProgressBar 组件 )(二)

三、完整代码示例


布局文件 :


<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:orientation="vertical">
    <!-- 直线进度条 -->
    <ProgressBar
        ohos:id="$+id:progressbar"
        ohos:height="match_content"
        ohos:width="match_parent"
        ohos:top_margin="200"
        ohos:layout_alignment="horizontal_center"
        ohos:min="0"
        ohos:max="100"
        ohos:progress="66"
        ohos:vice_progress="88"/>
    <!-- 圆形进度条 -->
    <RoundProgressBar
        ohos:id="$+id:roundprogressbar"
        ohos:height="400"
        ohos:width="400"
        ohos:top_margin="200"
        ohos:layout_alignment="horizontal_center"
        ohos:min="0"
        ohos:max="100"
        ohos:progress="66"/>
</DirectionalLayout>


Java 代码 :


package com.example.progressbar.slice;
import com.example.progressbar.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.ProgressBar;
import ohos.agp.components.RoundProgressBar;
public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        // 获取 XML 布局中的 ProgressBar 按钮
        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressbar);
        // 设置最大值最小值
        progressBar.setMaxValue(100);
        progressBar.setMinValue(0);
        // 设置当前进度
        progressBar.setProgressValue(20);
        // 设置第二进度值
        progressBar.setViceProgress(80);
        // 获取 XML 布局中的 RoundProgressBar 按钮
        RoundProgressBar roundProgressBar = (RoundProgressBar) findComponentById(ResourceTable.Id_roundprogressbar);
        // 设置最大值最小值
        roundProgressBar.setMaxValue(20);
        roundProgressBar.setMinValue(0);
        // 设置当前进度
        roundProgressBar.setProgressValue(10);
        // 设置第二进度
        roundProgressBar.setViceProgress(15);
    }
    @Override
    public void onActive() {
        super.onActive();
    }
    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}



image.png




四、GitHub 地址


GitHub 主应用 : https://github.com/han1202012/HarmonyHelloWorld


CheckBox 组件示例 Module : https://github.com/han1202012/HarmonyHelloWorld/tree/master/progressbar


目录
相关文章
|
10月前
|
开发者 容器
鸿蒙应用开发从入门到实战(十四):ArkUI组件Column&Row&线性布局
ArkUI提供了丰富的系统组件,用于制作鸿蒙原生应用APP的UI,本文主要讲解Column和Row组件的使用以及线性布局的方法。
806 12
|
10月前
|
API 数据处理
鸿蒙应用开发从入门到实战(十三):ArkUI组件Slider&Progress
ArkUI提供了丰富的系统组件,用于制作鸿蒙原生应用APP的UI,本文主要讲解滑块Slider和进度条Progress组件的使用。
402 1
|
10月前
|
数据安全/隐私保护 开发者
鸿蒙应用开发从入门到实战(十一):ArkUI组件Text&TextInput
ArkUI提供了丰富的系统组件,用于制作鸿蒙原生应用APP的UI,本文主要讲解文本组件Text和TextInput的使用。
581 3
|
10月前
|
存储 缓存 5G
鸿蒙 HarmonyOS NEXT端云一体化开发-云存储篇
本文介绍用户登录后获取昵称、头像的方法,包括通过云端API和AppStorage两种方式,并实现上传头像至云存储及更新用户信息。同时解决图片缓存问题,添加上传进度提示,支持自动登录判断,提升用户体验。
408 1
|
10月前
|
存储 负载均衡 数据库
鸿蒙 HarmonyOS NEXT端云一体化开发-云函数篇
本文介绍基于华为AGC的端云一体化开发流程,涵盖项目创建、云函数开通、应用配置及DevEco集成。重点讲解云函数的编写、部署、调用与传参,并涉及环境变量设置、负载均衡、重试机制与熔断策略等高阶特性,助力开发者高效构建稳定云端服务。
888 1
鸿蒙 HarmonyOS NEXT端云一体化开发-云函数篇
|
10月前
|
存储 JSON 数据建模
鸿蒙 HarmonyOS NEXT端云一体化开发-云数据库篇
云数据库采用存储区、对象类型、对象三级结构,支持灵活的数据建模与权限管理,可通过AGC平台或本地项目初始化,实现数据的增删改查及端侧高效调用。
560 1
|
10月前
|
存储 开发者 容器
鸿蒙 HarmonyOS NEXT星河版APP应用开发-ArkTS面向对象及组件化UI开发使用实例
本文介绍了ArkTS语言中的Class类、泛型、接口、模块化、自定义组件及状态管理等核心概念,并结合代码示例讲解了对象属性、构造方法、继承、静态成员、访问修饰符等内容,同时涵盖了路由管理、生命周期和Stage模型等应用开发关键知识点。
659 1
鸿蒙 HarmonyOS NEXT星河版APP应用开发-ArkTS面向对象及组件化UI开发使用实例
|
10月前
|
JavaScript
鸿蒙应用开发从入门到实战(八):ArkTS自定义组件语法
ArkUI除系统预置的组件外,还支持自定义组件。使用自定义组件,可使代码的结构更加清晰,并且能提高代码的复用性。
423 7
|
10月前
|
API 数据处理
鸿蒙应用开发从入门到实战(十三):ArkUI组件Slider&Progress
ArkUI提供滑块Slider与进度条Progress组件,用于鸿蒙原生APP开发。Slider支持拖动调节音量、亮度等,可设步长、方向及提示气泡;Progress支持线性、环形等多种样式,可自定义颜色、宽度与刻度,实时显示任务进度。
590 2
|
10月前
|
开发者
鸿蒙应用开发从入门到实战(十二):ArkUI组件Button&Toggle
ArkUI提供了丰富的系统组件,用于制作鸿蒙原生应用APP的UI,本文主要讲解按钮组件Button和Toggle的使用。
645 2

热门文章

最新文章