当前位置:   article > 正文

鸿蒙os2.0页面加载以及跳转背后的执行流程图_鸿蒙 app第二次运行界面错乱

鸿蒙 app第二次运行界面错乱

本来比这个全,结果画着画着我双击了,然后我以为是图片没了呢我想还是重新弄吧,结果就由重新截图,发现是真的没了,第一次其实已经是画好了,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"
      }
    ]
  }
}
  • 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

(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());

    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

(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);
            }
        });

    }
}

  • 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

(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());
   }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

(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);
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

(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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

github项目地址

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/335149
推荐阅读
相关标签
  

闽ICP备14008679号