【鸿蒙应用开发】【HCIA认证】模拟题每日1练(第55题) 原创

鸿蒙张荣超
发布于 2021-10-19 10:51
浏览
2收藏

【鸿蒙应用开发】【HCIA认证】模拟题每日1练(第55题)-鸿蒙开发者社区

这道题的说法是正确的。

 

  • 多个动画同时开始同时执行动画1和动画2。

动画1:沿x轴从100移动到800位置

动画2:沿y轴从100移动到800位置
MainAbilitySlice.java的示例代码如下:

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorGroup;
import ohos.agp.animation.AnimatorProperty;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;

public class MainAbilitySlice extends AbilitySlice {
    private boolean started =false;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        //创建播放动画的组件
        Image image = new Image(getContext());
        image.setPixelMap(ResourceTable.Media_icon);
        image.setLayoutConfig(new ComponentContainer.LayoutConfig(200, 200));
        DirectionalLayout layout = new DirectionalLayout(getContext());
        layout.setLayoutConfig(new ComponentContainer.LayoutConfig(
                ComponentContainer.LayoutConfig.MATCH_PARENT,
                ComponentContainer.LayoutConfig.MATCH_PARENT
        ));
        layout.addComponent(image);
        super.setUIContent(layout);
        //创建动画组对象
        AnimatorGroup animatorGroup = new AnimatorGroup();
        //动画1 - 沿x轴从100移动到800位置
        AnimatorProperty action1 = new AnimatorProperty();
        action1.setTarget(image);
        action1.moveFromX(0).moveToX(800);
        //动画2 - 沿y轴从100移动到800位置
        AnimatorProperty action2 = new AnimatorProperty();
        action2.setTarget(image);
        action2.moveFromY(0).moveToY(800);
        //同时执行动画1和动画2
        animatorGroup.runParallel(action1, action2);
        //无限循环
        animatorGroup.setLoopedCount(Animator.INFINITE);
        //时长
        animatorGroup.setDuration(1500);
        //点击图片开始/停止动画
        image.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (!started) {
                    //启动动画组
                    animatorGroup.start();
                } else {
                    //停止动画组
                    animatorGroup.stop();
                }
                started = !started;
            }
        });
    }
}

 

 

  • 多个动画按顺序逐个执行
    先执行动画1,然后执行动画2。

动画1:沿x轴从100移动到800位置

动画2:沿y轴从100移动到800位置

MainAbilitySlice.java的示例代码如下:

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorGroup;
import ohos.agp.animation.AnimatorProperty;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;

public class MainAbilitySlice extends AbilitySlice {
    private boolean started =false;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        //创建播放动画的组件
        Image image = new Image(getContext());
        image.setPixelMap(ResourceTable.Media_icon);
        image.setLayoutConfig(new ComponentContainer.LayoutConfig(200, 200));
        DirectionalLayout layout = new DirectionalLayout(getContext());
        layout.setLayoutConfig(new ComponentContainer.LayoutConfig(
                ComponentContainer.LayoutConfig.MATCH_PARENT,
                ComponentContainer.LayoutConfig.MATCH_PARENT
        ));
        layout.addComponent(image);
        super.setUIContent(layout);
        //创建动画组对象
        AnimatorGroup animatorGroup = new AnimatorGroup();
        //动画1 - 沿x轴从100移动到800位置
        AnimatorProperty action1 = new AnimatorProperty();
        action1.setTarget(image);
        action1.moveFromX(0).moveToX(800);
        //动画2 - 沿y轴从100移动到800位置
        AnimatorProperty action2 = new AnimatorProperty();
        action2.setTarget(image);
        action2.moveFromY(0).moveToY(800);
        //先动画1后动画2
        animatorGroup.runSerially(action1, action2);
        //无限循环
        animatorGroup.setLoopedCount(Animator.INFINITE);
        //时长
        animatorGroup.setDuration(1500);
        //点击图片开始/停止动画
        image.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (!started) {
                    //启动动画组
                    animatorGroup.start();
                } else {
                    //停止动画组
                    animatorGroup.stop();
                }
                started = !started;
            }
        });
    }
}

 

为了更加灵活处理多个动画的播放顺序,例如一些动画顺序播放,一些动画同时播放,Java UI框架提供了更方便的动画Builder接口:

  • 先同时执行动画1和动画2,然后同时执行动画3和动画4。
    动画1:沿x轴从100移动到800位置

动画2:沿y轴从100移动到800位置

动画3:沿y轴从0.3放大到1.0

动画4:沿x轴从0.3放大到1.0

MainAbilitySlice.java的示例代码如下:

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorGroup;
import ohos.agp.animation.AnimatorProperty;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;

public class MainAbilitySlice extends AbilitySlice {
    private boolean started =false;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        //创建播放动画的组件
        Image image = new Image(getContext());
        image.setPixelMap(ResourceTable.Media_icon);
        image.setLayoutConfig(new ComponentContainer.LayoutConfig(200, 200));
        DirectionalLayout layout = new DirectionalLayout(getContext());
        layout.setLayoutConfig(new ComponentContainer.LayoutConfig(
                ComponentContainer.LayoutConfig.MATCH_PARENT,
                ComponentContainer.LayoutConfig.MATCH_PARENT
        ));
        layout.addComponent(image);
        super.setUIContent(layout);
        //创建动画组对象
        AnimatorGroup animatorGroup = new AnimatorGroup();
        //动画1 - 沿x轴从100移动到800位置
        AnimatorProperty action1 = new AnimatorProperty();
        action1.setTarget(image);
        action1.moveFromX(0).moveToX(800);
        //动画2 - 沿y轴从100移动到800位置
        AnimatorProperty action2 = new AnimatorProperty();
        action2.setTarget(image);
        action2.moveFromY(0).moveToY(800);
        //动画3 - 沿y轴从0.3放大到1.0
        AnimatorProperty action3 = new AnimatorProperty();
        action3.setTarget(image);
        action3.scaleYFrom(0.3f).scaleY(1.0f);
        //动画4 - 沿x轴从0.3放大到1.0
        AnimatorProperty action4 = new AnimatorProperty();
        action4.setTarget(image);
        action4.scaleXFrom(0.3f).scaleX(1.0f);

        //先同时执行动画1和动画2,然后同时执行动画3和动画4
        AnimatorGroup.Builder builder = animatorGroup.build();
        builder.addAnimators(action1,action2).addAnimators(action3,action4);
        //无限循环
        animatorGroup.setLoopedCount(Animator.INFINITE);
        //时长
        animatorGroup.setDuration(1500);
        //点击图片开始/停止动画
        image.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (!started) {
                    //启动动画组
                    animatorGroup.start();
                } else {
                    //停止动画组
                    animatorGroup.stop();
                }
                started = !started;
            }
        });
    }
}

 

 

向大家推荐由我的教学团队开发的视频课程《鸿蒙应用开发HCIA认证超细致精讲》:

https://edu.51cto.com/topic/4940.html

 

 

————————————————————————————————————————————————————————————————————

    什么是鸿蒙应用开发HCIA认证呢?华为认证分为两大类,分别是:云服务与平台、ICT技术架构与应用。这两大类总共覆盖了20多个技术领域,包括大家熟知的:大数据、AI、云、智能计算、WLAN、安全、5G、等。这20多个技术领域中的每个技术领域,都由低到高分为3个等级:HCIA、HCIP、HCIE,其中,HCIA是华为认证的ICT工程师,HCIP是华为认证的高级工程师,HCIE是华为认证的ICT专家。ICT的全称是Information Communication Technology,也就是信息通信技术。
    随着鸿蒙的日趋流行,HarmonyOS被放在了华为认证第一的位置上,可见其重要性。HarmonyOS这个领域也由低到高分为3个等级:HCIA、HCIP、HCIE,分别表示工程师、高级工程师、专家。通过HCIA,说明你具有熟练的开发经验,扎实的理论基础;通过HCIP,说明你已经掌握复杂场景开发的能力;通过HCIE,说明你已经是全场景解决方案的专家,已经掌握了规划设计与系统调优的能力。目前,华为官方只发布了鸿蒙的HCIA,后续会逐渐发布鸿蒙的HCIP和HCIE。其中,HCIA又分为鸿蒙应用开发工程师和鸿蒙设备开发工程师。

    为什么要考鸿蒙应用开发HCIA认证呢?我觉得有这么几个主要原因。首先,这个认证在一定程度上证明了你的技术能力,尤其是当你去求职的时候,你说你行,怎么证明你行呢?认证的证书可以在一定程度上证明你行。考取鸿蒙认证的第2个主要原因是:抓住鸿蒙的红利期,物以稀为贵。如果你想赶上这波红利期,想要加入到鸿蒙的这波浪潮里,考取一个鸿蒙的认证,或多或少可以为你增添一些竞争的筹码。考取鸿蒙认证的第3个原因,也是我个人认为最重要的原因,它是系统学习和能力提升的绝佳方式!华为官方给出了认证考试的考试大纲,大纲中明确列出了考查的技能及需要掌握的知识点,最重要的是,大纲中列出的考点都是工作中必备的核心技能,只要你按照考试大纲去准备,把考查的技能知识点全部都掌握,就能在一段时期内达到一定的水平,而且不会让你的学习跑偏!在鸿蒙认证发布之前,相信很多朋友学习鸿蒙都是漫无目的的、没有目标的,所以学习效率很低!现在有了鸿蒙认证,即便你不考也没有关系,完全可以按照考试大纲去系统学习,从而提高你的学习效率,让自己的鸿蒙学习之路始终在一个正确的轨道上,不跑偏!至于全部学完之后,是否要考个认证,可以到时候再说,先按照考试大纲学起来!

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
标签
已于2021-10-19 10:51:36修改
2
收藏 2
回复
举报
回复
    相关推荐