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

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

尝试用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>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.

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);
    }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
已于2021-12-9 17:48:32修改
分享
微博
QQ
微信
回复
2021-12-09 15:51:57
相关问题
请问鸿蒙中有没有@Keep注解
9368浏览 • 2回复 待解决
HarmonyOS中有没有WeakRef
897浏览 • 1回复 待解决
鸿蒙生态中有没有react-native适配?
14427浏览 • 1回复 待解决
HarmonyOS 有没有密码控件
860浏览 • 1回复 待解决
HarmonyOS 有没有图片裁剪控件
778浏览 • 1回复 待解决
HarmonyOS 中有没有类似tint的属性
933浏览 • 1回复 待解决
鸿蒙java中有没有控制4G/5G开关的接口
5991浏览 • 1回复 待解决
HarmonyOS 有没有隐私政策弹的demo?
810浏览 • 1回复 待解决
API中有没有分辨率设置?
682浏览 • 1回复 待解决