#2020征文-手机#鸿蒙Java开发模式三:动画组件页面及跳转页面

六合李欣
发布于 2021-1-16 17:33
浏览
0收藏

1.界面效果

#2020征文-手机#鸿蒙Java开发模式三:动画组件页面及跳转页面-鸿蒙开发者社区

 

#2020征文-手机#鸿蒙Java开发模式三:动画组件页面及跳转页面-鸿蒙开发者社区

2. 引入自定义动画组件,也可以自行构建HAP包

#2020征文-手机#鸿蒙Java开发模式三:动画组件页面及跳转页面-鸿蒙开发者社区

3.首页布局文件和动画组件

<?xml version="1.0" encoding="utf-8"?>
<DependentLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:width="match_parent"
    ohos:height="match_parent"
    ohos:background_element="#F0FFFF">


    <com.isoftstone.loadingview.LoadingView
        ohos:id="$+id:text_helloworld"
        ohos:height="400"
        ohos:width="600"
        ohos:center_in_parent="true"
        />

    <com.isoftstone.loadingview.LoadingView
        ohos:id="$+id:text_circle"
        ohos:height="400"
        ohos:width="800"
        ohos:below="$id:text_helloworld"
        ohos:center_in_parent="true"
        />


</DependentLayout>

 

3.Java代码

package com.example.htmljava8.slice;

import com.example.htmljava8.ResourceTable;
import com.isoftstone.loadingview.LoadingView;
import com.isoftstone.precentpositionlayout.PrecentPositionLayout;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Text;

public class MainAbilitySlice extends AbilitySlice {


    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        initView();
    }

    private void  initView()  {

        LoadingView loadingView1 = (LoadingView)findComponentById(ResourceTable.Id_text_helloworld);
        loadingView1.SetType(LoadingView.LoadingViewType.WATER);
        loadingView1.addDrawTask(loadingView1);

        LoadingView loadingView4 = (LoadingView)findComponentById(ResourceTable.Id_text_circle);
        loadingView4.SetType(LoadingView.LoadingViewType.CIRCLE);
        loadingView4.addDrawTask(loadingView4);


        new  Thread(new Runnable() {
            @Override
            public void run() {

                try {
                    Thread.sleep(8000);

                    //启动一个页面
                    Intent secondIntent = new Intent();
                    // 指定待启动FA的bundleName和abilityName
                    Operation operation = new Intent.OperationBuilder()
                            .withDeviceId("")
                            .withBundleName("com.example.htmljava8")
                            .withAbilityName("com.example.htmljava8.AppTwo")

                            .build();
                    secondIntent.setOperation(operation);
                    startAbility(secondIntent); // 通过AbilitySlice的startAbility接口实现启动另一个页面

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();


//       getUITaskDispatcher().asyncDispatch(new Runnable() {
//           @Override
//           public void run() {
//
//
//
//
//           }
//       });


    }
    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}

 

4.跳转第二个界面代码

<?xml version="1.0" encoding="utf-8"?>
<DependentLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:background_element="#96CDCD"
    >

    <Text
        ohos:id="$+id:text_helloworld"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:layout_alignment="horizontal_center"
        ohos:text="全力以赴,全世界都会为你让路!"
        ohos:text_size="75"
        ohos:center_in_parent="true"
        />

    </DependentLayout>
package com.example.htmljava8.slice;

import com.example.htmljava8.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;

public class AppTwoSlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_app_two);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}

标签
已于2021-1-20 16:09:07修改
2
收藏
回复
举报
回复
    相关推荐