当前位置:网站首页>Hongmeng learning notes: creating layouts using XML
Hongmeng learning notes: creating layouts using XML
2022-06-25 06:39:00 【InfoQ】
Preface
- Component It's an object drawn on the screen , Users can interact with it .
- ComponentContainer It's one for holding other Component and ComponentContainer Object's container .

Java UI Layout
XML Create a layout

<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:orientation="vertical">
</DirectionalLayout>
Join in Text Child components
- Identity properties : ohos:id="$+id:text" , Set the identity for this component text , stay Java This can be used in the code id Identity acquisition XML Components defined in the layout ; among + The function of the number is if id If it doesn't exist, it generates id Constant , If it's time to id If it exists, use the existing constant ; stay Java The generated constant can be used to obtain the component in the code ;
- Width and height properties : The width fills the parent container ohos:width=“match_parent” ; High package content ohos:height=“match_content” ;
- Text content properties : This is a Text Unique properties of components , ohos:text=“ Custom layout Text Components ” , Show " Custom layout Text Components " written words ;
- Text font size attribute : This is a Text Unique properties of components , ohos:text_size=“100” ;
- Text alignment properties : This is a Text Unique properties of components , ohos:text_alignment=“center” In the middle ;
<Text
ohos:id="$+id:text"
ohos:width="match_content"
ohos:height="match_content"
ohos:text_color="#FFDE1968"
ohos:text=" Learn Hongmeng together "
ohos:text_size="40fp"
ohos:center_in_parent="true"
/>
Join in Button Child components
<Button
ohos:id="$+id:button"
ohos:width="match_content"
ohos:height="match_content"
ohos:text=" Click here for a surprise "
ohos:text_size="19fp"
ohos:text_color="#FF0C43CF"
ohos:top_padding="8vp"
ohos:bottom_padding="8vp"
ohos:right_padding="70vp"
ohos:left_padding="70vp"
ohos:center_in_parent="true"
ohos:below="$id:text"
ohos:margin="10vp"/>
<?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:orientation="vertical"
ohos:padding="32">
<Text
ohos:id="$+id:text"
ohos:width="match_content"
ohos:height="match_content"
ohos:text_color="#FFDE1968"
ohos:text=" Learn Hongmeng together "
ohos:text_size="40fp"
ohos:center_in_parent="true"
/>
<Button
ohos:id="$+id:button"
ohos:width="match_content"
ohos:height="match_content"
ohos:text=" Click here for a surprise "
ohos:text_size="19fp"
ohos:text_color="#FF0C43CF"
ohos:top_padding="8vp"
ohos:bottom_padding="8vp"
ohos:right_padding="70vp"
ohos:left_padding="70vp"
ohos:center_in_parent="true"
ohos:below="$id:text"
ohos:margin="10vp"/>
</DependentLayout>
establish Ability

XMLAbility
XMLAbility.javaXMLAbilitySlice.java
{
"orientation": "unspecified",
"name": "com.example.helloworld.XMLAbility",
"icon": "$media:icon",
"description": "$string:xmlability_description",
"label": "$string:entry_XMLAbility",
"type": "page",
"launchType": "standard"
}
config.json{
"app": {
"bundleName": "com.example.helloworld",
"vendor": "example",
"version": {
"code": 1000000,
"name": "1.0.0"
}
},
"deviceConfig": {},
"module": {
"package": "com.example.helloworld",
"name": ".MyApplication",
"mainAbility": "com.example.helloworld.MainAbility",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": true
},
"abilities": [
{
"orientation": "unspecified",
"name": "com.example.helloworld.XMLAbility",
"icon": "$media:icon",
"description": "$string:xmlability_description",
"label": "$string:entry_XMLAbility",
"type": "page",
"launchType": "standard"
},
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"name": "com.example.helloworld.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "standard"
}
]
}
}
XMLAbility Load the layout file
package com.example.helloworld;
import com.example.helloworld.slice.XMLAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
public class XMLAbility extends Ability {
@Override
public void onStart(Intent intent) {
super.onStart(intent);
// super.setMainRoute(XMLAbilitySlice.class.getName());
// Displays custom ability_xml.xml Layout file
super.setUIContent(ResourceTable.Layout_ability_xml);
}
}
Run code :

summary
边栏推荐
- ASP. Net core - Safety of asynclocal in asp NET Core
- ARM processor operating mode
- [轻松学会shell编程]-5、计划任务
- 【ROS2】为什么要使用ROS2?《ROS2系统特性介绍》
- System dilemma and software complexity: Why are our systems so complex?
- Understand what MSS is
- Grouped uitableview has 20px of extra padding at the bottom
- Cannot activate inspection type when SAP retail uses transaction code mm41 to create commodity master data?
- 集群常用群起脚本
- Sophomores majoring in mechanics build a manipulator by hand -- full of compromise
猜你喜欢

What is the slice flag bit

System dilemma and software complexity: Why are our systems so complex?

sin(a+b)=sina*cosb+sinb*cosa的推导过程

3dmax软件的制作木桶过程:三步流程

Derivation of COS (a-b) =cosa*cosb+sina*sinb

Ht81293 built in adaptive dynamic boost 20W mono class D power amplifier IC solution

Ht8513 single lithium battery power supply with built-in Dynamic Synchronous Boost 5W mono audio power amplifier IC solution

@Detailed explanation of valid annotation usage

We cannot activate inspection type for article master in transaction code MM41?

Uncaught TypeError: Cannot read properties of undefined (reading ‘prototype‘)
随机推荐
Comparison test of mono 120W high power class D power amplifier chip cs8683-tpa3116
Understand what MTU is
[从零开始学习FPGA编程-43]:视野篇 - 后摩尔时代”芯片设计的技术演进-2-演进方向
We cannot activate inspection type for article master in transaction code MM41?
Query process of MySQL secondary index
What is the IP address
@The difference between notempty, @notnull and @notblank
Derivation of sin (a-b) =sina*cosb-sinb*cosa
Viewing Chinese science and technology from the Winter Olympics (V): the Internet of things
MSG_ OOB MSG_ PEEK
Drosophila played VR and entered nature. It was found that there were attention mechanisms and working memory. The insect brain was no worse than that of mammals
Laravel8+ wechat applet generates QR code
Sophomores majoring in mechanics build a manipulator by hand -- full of compromise
Ht513 I2S input 2.8W mono class D audio power amplifier IC
How to use asemi FET 7n80 and how to use 7n80
Analysis of common interview questions in redis
Usage of STL map
ACWING/2004. 错字
BigDecimal. Summary of setscale usage
How to find happiness in programming and get lasting motivation?