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

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

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

最终我重新又画了一张

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

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


<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


<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项目地址

你可能感兴趣的:(后端)