Components ProgressBar and RoundProgressBar

Author: Han Ru

Company: Program Ka (Beijing) Technology Co., LTD

Hong Meng Bus columnist

The ProgressBar is used to show the progress of content or operations.

A, ProgressBar

1.1 Supported XML attributes

The common XML attributes of progressBars inherit from: ScrollView

The ProgressBar’s own XML attributes are shown in the following table:

The attribute name Product description The values The values that Use case
divider_lines_enabled The divider Boolean type You can set true/false directly or refer to a Boolean resource. ohos:divider_lines_enabled=”true”

ohos:divider_lines_enabled=”$boolean:true”
divider_lines_number Number of dividing lines The integer types You can set integer values directly or refer to an INTEGER resource. ohos:divider_lines_number=”1″

ohos:divider_lines_number=”$integer:one”
infinite Whether to use indeterminate mode Boolean type You can set true/false directly or refer to a Boolean resource. ohos:infinite=”true”

ohos:infinite=”$boolean:true”
infinite_element Uncertain mode Configuration Prerequisite: Infinite must be set to true Element type You can reference only the image resources under media/ Graphic. ohos:infinite_element=”
m e d i a : m e d i a s r c o h o s : i n f i n i t e e l e m e n t = media:media_src”ohos:infinite_element=”
graphic:graphic_src”
max The maximum The integer types You can set integer values directly or refer to an INTEGER resource. ohos:max=”1″ohos:max=”$integer:one”
max_height Maximum height A float A float type representing the size. They can be floating point values, which default to px; It can also be a floating point value with px/ VP /fp units; Float resources can also be referenced. ohos:max_height=”100″

ohos:max_height=”20vp”

ohos:max_height=”$float:size_value”
max_width Maximum width A float A float type representing the size. They can be floating point values, which default to px; It can also be a floating point value with px/ VP /fp units; Float resources can also be referenced. ohos:max_width=”100″ohos:max_width=”20vp”

ohos:max_width=”$float:size_value”
min The minimum value The integer types You can set integer values directly or refer to an INTEGER resource. ohos:min=”1″ohos:min=”$integer:one”
orientation An orientation horizontal Indicates that the ProgressBar is displayed horizontally. ohos:orientation=”horizontal”
vertical Indicates that the ProgressBar is displayed vertically.
progress The current progress The integer types You can set integer values directly or refer to an INTEGER resource. ohos:progress=”10″ohos:progress=”$integer:ten”
background_instruct_element background Element type Can directly configure the color value, also can reference color resources or reference media/graphic image resources. ohos:background_instruct_element=”#000000″

ohos:background_instruct_element=”
c o l o r : b l a c k o h o s : b a c k g r o u n d i n s t r u c t e l e m e n t = color:black”ohos:background_instruct_element=”
media:media_src”ohos:background_instruct_element=”$graphic:graphic_src”
progress_width Progress bar width A float A float type representing the size. They can be floating point values, which default to px; It can also be a floating point value with px/ VP /fp units; Float resources can also be referenced. ohos:progress_width=”100″

ohos:progress_width=”20vp”

ohos:progress_width=”$float:size_value”
progress_color Progress bar color Color type You can set the color value directly or reference the color resource. ohos:progress_color=”#FF262626″

ohos:progress_color=”$color:black”
progress_element Progress bar background Element type Can directly configure the color value, also can reference color resources or reference media/graphic image resources. ohos:progress_element=”#000000″ohos:progress_element=”
c o l o r : b l a c k o h o s : p r o g r e s s e l e m e n t = color:black”ohos:progress_element=”
media:media_src”ohos:progress_element=”$graphic:graphic_src”
progress_hint_text Progress text Type string You can set a text string directly, or you can reference a String resource. ohos:progress_hint_text=”test”

ohos:progress_hint_text=”$string:test_str”
progress_hint_text_alignment Progress prompt text alignment left Indicates that text is aligned to the left. Can set the value of items such as listed in the table, you can also use the multiple combination “|”.

ohos:progress_hint_text_alignment=”top”

ohos:progress_hint_text_alignment=”top|left”
top Indicates that text is aligned at the top.
right Indicates that text is justified to the right.
bottom Indicates that text is aligned against the bottom.
horizontal_center Indicates that text is horizontally centered.
vertical_center Indicates that text is vertically centered.
center Indicates that text is centered.
progress_hint_text_color Progress prompt text color Color type You can set the color value directly or reference the color resource. ohos:progress_hint_text_color=”#FFFFFFFF”

ohos:progress_hint_text_color=”$color:black”
vice_progress Current secondary progress The integer types You can set integer values directly or refer to an INTEGER resource. ohos:vice_progress=”1″

ohos:vice_progress=”$integer:one”
vice_progress_element Secondary progress bar background Element type Can directly configure the color value, also can reference color resources or reference media/graphic image resources. ohos:vice_progress_element=”#000000″

ohos:vice_progress_element=”
c o l o r : b l a c k < b r / > o h o s : v i c e p r o g r e s s e l e m e n t = color:black”<br />ohos:vice_progress_element=”
media:media_src”

ohos:vice_progress_element=”$graphic:graphic_src”
step The step size of the progress The integer types You can set integer values directly or refer to an INTEGER resource. The default value is 1. If step is set to 10, the progress value is a multiple of 10. ohos:step=”1″ohos:step=”$integer:one”
progress_hint_text_size Progress prompt text size A float A float type representing the size. They can be floating point values, which default to px; It can also be a floating point value with px/ VP /fp units; Float resources can also be referenced. ohos:progress_hint_text_size=”100″

ohos:progress_hint_text_size=”20fp”

ohos:progress_hint_text_size=”$float:size_value”

1.2 create a ProgressBar

Create a ProgressBar in an XML file in the Layout directory.

<ProgressBar
        ohos:progress_width="10vp"
        ohos:height="60vp"
        ohos:width="match_parent"
        ohos:max="100"
        ohos:min="0"
        ohos:progress="60"
        ohos:top_margin="30vp"/>
Copy the code

Create ProgressBar effect:

1.3 set the ProgressBar

1. Set the ProgressBar direction to vertical.

<ProgressBar
        ohos:orientation="vertical"
        ohos:top_margin="20vp"
        ohos:height="150vp"
        ohos:width="60vp"
        ohos:progress_width="10vp"
        ohos:max="100"
        ohos:min="0"
        ohos:progress="60"/>
Copy the code

Vertical ProgressBar effect:

2. Set the current progress

Setup in XML:

<ProgressBar
    ...
    ohos:progress="60"/>
Copy the code

Or set it in Java:

progressBar.setProgressValue(60);
Copy the code

3. Set the maximum and minimum values

Set in XML:

<ProgressBar
    ...
    ohos:max="400"
    ohos:min="0"/>
Copy the code

Or set it in Java:

progressBar.setMaxValue(400);
progressBar.setMinValue(0);
Copy the code

4. Set the ProgressBar progress color

<ProgressBar
    .
    ohos:progress_element="#FF9900" />
Copy the code

Set ProgressBar color effects:

5. Set the ProgressBar base color

<ProgressBar
    ...
    ohos:background_instruct_element="# 000000" />
Copy the code

Set the background color effect:

6. Set the ProgressBar split line

Configure in XML:

<ProgressBar
    ...
    ohos:divider_lines_enabled="true"
    ohos:divider_lines_number="5" />
Copy the code

Configure in Java code:

progressBar.enableDividerLines(true);
progressBar.setDividerLinesNumber(5);
Copy the code

Add the dividing line effect:

7. Set the ProgressBar split line color

progressBar.setDividerLineColor(Color.MAGENTA);
Copy the code

Set the dividing line color effect:

8. Set ProgressBar prompt text

<ProgressBar
    ...
    ohos:progress_hint_text="20%"
    ohos:progress_hint_text_color="#FFCC99" />
Copy the code

Set prompt text effect:

Second, the RoundProgressBar

The RoundProgressBar is derived from the ProgressBar and has the same properties as the ProgressBar. When setting the same properties, the RoundProgressBar is used to display circular progress.

2.1 Supported XML Attributes

The common XML attributes of RoundProgressBar inherit from: ProgressBar

The RoundProgressBar’s own XML attributes are shown in the following table:

The attribute name Product description The values The values that Use case
start_angle The starting Angle of the circular progress bar A float Floating-point values can be set directly, or float floating-point resources can be referenced. ohos:start_angle=”10″

ohos:start_angle=”$float:float_num”
max_angle Maximum Angle of the circular progress bar A float Floating-point values can be set directly, or float floating-point resources can be referenced. Ohos: start_angle = “360.0”

ohos:start_angle=”$float:float_num”

2.2 create RoundProgressBar

<RoundProgressBar
        ohos:id="$+id:round_progress_bar"
        ohos:height="200vp"
        ohos:width="200vp"
        ohos:progress_width="10vp"
        ohos:progress="20"
        ohos:progress_color="#00FF00"/>
Copy the code

Create the RoundProgressBar effect:

2.3 set RoundProgressBar

1. Set the start and end angles

<RoundProgressBar
    ...
    ohos:start_angle="45"
    ohos:max_angle="270"
    ohos:progress="20"
    ohos:progress_hint_text="Round"
    ohos:progress_hint_text_color="#007DFF" />
Copy the code

Set Angle effect:

I originally wrote an example to simulate downloading data and loading a progress bar. After writing it, I found that EventHandler was used, so I moved this example to the EventHandler section. 😂

More:

1. Community: Hongmeng Bus www.harmonybus.net/

2. HarmonyBus

3, technical exchange QQ group: 714518656

4. Video courses: www.chengxuka.com