{
"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"
}
]
}
}
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());
}
}
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);
}
});
}
}
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());
}
}
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);
}
}
<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>
<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项目地址