鸿蒙os2.0页面加载以及跳转背后的执行流程图

本来比这个全,结果画着画着我双击了,然后我以为是图片没了呢我想还是重新弄吧,结果就由重新截图,发现是真的没了,第一次其实已经是画好了,ctrl v一下就可以了,但是我又截图了一次,导致第一次画的丢失,幸亏中间画了一半我拍了张照片

在这里插入图片描述

最终我重新又画了一张

在这里插入图片描述

3.直接上代码:

(1).config.js

{
  "app": {
    "bundleName": "com.ttit",
    "vendor": "ttit",
    "version": {
      "code": 1,
      "name": "1.0"
    },
    "apiVersion": {
      "compatible": 3,
      "target": 3
    }
  },
  "deviceConfig": {},
  "module": {
    "package": "com.ttit",
    "name": ".helloworld_harmonyos",
    "reqCapabilities": [
      "video_support"
    ],
    "deviceType": [
      "tv"
    ],
    "distro": {
      "deliveryWithInstall": true,
      "moduleName": "entry",
      "moduleType": "entry"
    },
    "abilities": [
      {
        "skills": [
          {
            "entities": [
              "entity.system.home"
            ],
            "actions": [
              "action.system.home"
            ]
          }
        ],
        "orientation": "landscape",
        "formEnabled": false,
        "name": "com.ttit.MainAbility",
        "icon": "$media:icon",
        "description": "$string:mainability_description",
        "label": "helloworld_harmonyos",
        "type": "page",
        "launchType": "standard"
      },
      {
        "skills": [
          {
            "actions": [
              "action.other.button"
            ]
          }
        ],
        "orientation": "landscape",
        "formEnabled": false,
        "name": "com.ttit.OtherAbility",
        "type": "page",
        "launchType": "standard"
      }
    ]
  }
}

(2)MainAbility.java 用来设置主路由

package com.ttit;

import com.ttit.slice.*;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.components.TextField;

public class MainAbility extends Ability {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setMainRoute(ClockSlice.class.getName());

    }
}

(3)ClockSlice.java

package com.ttit.slice;

import com.ttit.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Clock;
import ohos.agp.components.Component;

public class ClockSlice extends AbilitySlice {
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_clock_layout);
        Clock clock = (Clock) findComponentById(ResourceTable.Id_clock);
        clock.set24HourModeEnabled(false);
        //自己测试

        Button btn =(Button)findComponentById(ResourceTable.Id_btn);

        btn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent in=new Intent();
                in.setAction("action.other.button");
                startAbility(in);
            }
        });

    }
}

(4) OtherAbility.java

package com.ttit;

import com.ttit.slice.ButtonSlice;
import com.ttit.slice.ImageSlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;

public class OtherAbility extends Ability {
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setMainRoute(ImageSlice.class.getName());
   }
}

(5)ImageSlice.java

package com.ttit.slice;

import com.ttit.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Image;

public class ImageSlice extends AbilitySlice {
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_image_layout);
        Image img = (Image) findComponentById(ResourceTable.Id_img);
//        img.setClipGravity(Image.GRAVITY_RIGHT);
        img.setScaleMode(Image.ScaleMode.STRETCH);
    }
}

(6) clock_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout xmlns:ohos="http://schemas.huawei.com/res/ohos"
                   ohos:width="match_parent"
                   ohos:height="match_parent"
                   ohos:orientation="vertical">

    <Clock
            ohos:id="$+id:clock"
            ohos:width="match_content"
            ohos:height="match_content"
            ohos:time="1598370054"
            ohos:text_color="#0000ff"
            ohos:text_size="30fp"
            ohos:time_zone="GMT"/>
    <Button
            ohos:id="$+id:btn"
            ohos:width="200vp"
            ohos:height="50vp"
            ohos:text="点击按钮"
            ohos:text_color="#ffffff"
            ohos:text_size="30fp"
            ohos:background_element="$graphic:shape_button_bg"
            />
</DirectionalLayout>

image_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout xmlns:ohos="http://schemas.huawei.com/res/ohos"
                   ohos:width="match_parent"
                   ohos:height="match_parent"
                   ohos:orientation="vertical">

    <Image
            ohos:id="$+id:img"
            ohos:width="200vp"
            ohos:height="200vp"
            ohos:image_src="$media:pic01"
            ohos:background_element="$graphic:shape_image_bg"
            />
</DirectionalLayout>

github项目地址

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值