鸿蒙中有没有载入框控件?

进行网络操作或者数据库操作的时候,有个载入旋转的的功能,鸿蒙中是什么?一直没有找到

尝试用Progressbar和RoundProgressBar好像都不行

鸿蒙
控件
2021-12-09 11:19:05
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
lengram
1

HarmonyOS目前没有载入框控件,您可以通过如下代码,实现类似功能:

1、ability_main.xml:

<?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:alignment="center"
    ohos:orientation="vertical">
    <ohos.agp.components.RoundProgressBar
        ohos:id="$+id:progress"
        ohos:height="300vp"
        ohos:width="300vp"
        ohos:layout_alignment="center"
        ohos:progress_width="20"
        >
    </ohos.agp.components.RoundProgressBar>
</DirectionalLayout>

2、MainAbilitySlice.java

package com.huawei.cookbook.slice;
import com.huawei.cookbook.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.RoundProgressBar;
import ohos.agp.components.element.PixelMapElement;
import ohos.global.resource.NotExistException;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
import ohos.media.image.ImageSource;
import ohos.media.image.PixelMap;
import ohos.media.image.common.Size;
import java.io.IOException;
import java.io.InputStream;
import java.util.Timer;
import java.util.TimerTask;
public class MainAbilitySlice extends AbilitySlice {
    private static final String TAG = MainAbilitySlice.class.getSimpleName();
    private static final HiLogLabel LABEL_LOG = new HiLogLabel(0, 0, TAG);
    private static final String LOG_FORMAT = "%{public}s: %{public}s";
    private RoundProgressBar roundProgressBar;
    private PixelMapElement element;
    private int rotateDegrees = 0;
    private int progressValue = 0;
    private int maxProgressVale = 100;
    @Override
    public void onStart(Intent intent) {
        setUIContent(ResourceTable.Layout_ability_main);
        roundProgressBar = (RoundProgressBar) findComponentById(ResourceTable.Id_progress);
        roundProgressBar.setMaxValue(maxProgressVale);
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                // 背景图片旋转角度
                if (rotateDegrees < 360) {
                    // 每秒旋转角度
                    rotateDegrees += 20;
                } else {
                    rotateDegrees = 0;
                }
                // 进度变化
                if (maxProgressVale > progressValue) {
                    progressValue += 10;
                } else {
                    progressValue = 0;
                }
                // 这里设置的背景图片可以根据自己的需求去选择图片
                element = new PixelMapElement(transIdToPixelMap(rotateDegrees, ResourceTable.Media_loading, 50, 50));
                element.setFilterPixelMap(true);
                getUITaskDispatcher().asyncDispatch(new Runnable() {
                    @Override
                    public void run() {
                        // 设置进度
                        roundProgressBar.setProgressValue(progressValue);
                        // 进度条背景图片
                        roundProgressBar.setBackground(element);
                    }
                });
            }
        }, 0, 1000);
        super.onStart(intent);
    }
    // 将本地图片resId转换成PixelMap
    private PixelMap transIdToPixelMap(int rotateDegrees, int resId, int width, int height) {
        InputStream source = null;
        ImageSource imageSource = null;
        try {
            source = getContext().getResourceManager().getResource(resId);
            imageSource = ImageSource.create(source, null);
            ImageSource.DecodingOptions decodingOpts = new ImageSource.DecodingOptions();
            decodingOpts.desiredSize = new Size(width, height);
            decodingOpts.rotateDegrees = rotateDegrees;
            return imageSource.createPixelmap(decodingOpts);
        } catch (IOException | NotExistException e) {
            HiLog.error(LABEL_LOG, LOG_FORMAT, TAG, "getPixelMap error");
        } finally {
            try {
                source.close();
            } catch (IOException e) {
                HiLog.error(LABEL_LOG, LOG_FORMAT, TAG,"getPixelMap source close error");
            }
        }
        return PixelMap.create(null);
    }
}
已于2021-12-9 17:48:32修改
分享
微博
QQ
微信
回复
2021-12-09 15:51:57
相关问题
请问鸿蒙中有没有@Keep注解
5822浏览 • 2回复 待解决
鸿蒙生态中有没有react-native适配?
10869浏览 • 1回复 待解决
鸿蒙java中有没有控制4G/5G开关的接口
3115浏览 • 1回复 待解决
鸿蒙-有没有缓存工具类
4087浏览 • 1回复 待解决
鸿蒙有没有类似carplay的应用
6099浏览 • 1回复 待解决
鸿蒙有没有类似viewpage的组件
5938浏览 • 1回复 已解决
鸿蒙有没有clipToPadding所对应的属性
3174浏览 • 1回复 待解决
有没有maobox 鸿蒙版的相关移植?
4281浏览 • 2回复 待解决
鸿蒙系统有没有调用锁屏的接口?
4999浏览 • 1回复 待解决
鸿蒙有没有相机免费推流sdk推荐?
2890浏览 • 1回复 待解决
有没有鸿蒙开发者微信群
9212浏览 • 4回复 待解决
有没有人想要鸿蒙系统内测邀请码?
6853浏览 • 5回复 待解决
有没有人成功调起了鸿蒙相机的
9414浏览 • 6回复 待解决
有没有调用日历的接口?
4422浏览 • 1回复 待解决