当前位置:网站首页>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
边栏推荐
- Meta universe is over, Web 3.0 will be fooled again?
- Detailed explanation of @jsoninclude annotation in Jackson
- Acwing / 2004. Mauvaise écriture
- Sleep quality today 67 points
- Metauniverse in 2022: robbing people, burning money and breaking through the experience boundary
- [speech discrimination] discrimination of speech signals based on MATLAB double threshold method [including Matlab source code 1720]
- How to realize hierarchical management of application and hardware in embedded projects
- Observation configuring wmic
- Understand what ICMP Protocol is
- With a younger brother OCR, say no to various types of verification codes!
猜你喜欢

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

アルマ / 炼金妹

有能力的人从不抱怨大环境!
![[speech discrimination] discrimination of speech signals based on MATLAB double threshold method [including Matlab source code 1720]](/img/36/ad86f403b47731670879f01299b416.jpg)
[speech discrimination] discrimination of speech signals based on MATLAB double threshold method [including Matlab source code 1720]

TCP BBR as rate based
![[core content and derivation] the mystery of human memory system may be just like this](/img/7c/98f27bb55a1a3b74c0ed8fd7fd2cc5.jpg)
[core content and derivation] the mystery of human memory system may be just like this

Gb28181 protocol -- timing

Cannot activate inspection type when SAP retail uses transaction code mm41 to create commodity master data?

【ROS2】为什么要使用ROS2?《ROS2系统特性介绍》

How to realize the stable output of 3.3v/3.6v (1.2-5v) voltage of lithium battery by using the voltage rise and fall chip cs5517
随机推荐
Advantages and disadvantages of using SNMP and WMI polling
The five minute demonstration "teaches" actors to speak foreign languages and can seamlessly switch languages. This AI dubbing company has just received a round a financing of 20million US dollars
How to realize the stable output of 3.3v/3.6v (1.2-5v) voltage of lithium battery by using the voltage rise and fall chip cs5517
Ht7180 3.7V L 12v/2a built in MOS high current boost IC solution
Aviator an expression evaluation engine
集群常用群起脚本
Understand what MSS is
Asemi fast recovery diode us1m parameters, us1m recovery time, us1m voltage drop
After five years of software testing in ByteDance, I was dismissed in December to remind my brother of paddling
What is the IP address
cos(a-b)=cosa*cosb+sina*sinb的推导过程
Why study discrete mathematics
Why can't GC () free memory- Why does gc() not free memory?
Single lithium battery 3.7V power supply 2x12w stereo boost audio power amplifier IC combination solution
Bcrypt password encryption kalrry
Viewing Chinese science and technology from the Winter Olympics (V): the Internet of things
With a younger brother OCR, say no to various types of verification codes!
@Detailed explanation of valid annotation usage
PHP converts strings to hex and hex to string - PHP convert string to hex and hex to string
Uncaught TypeError: Cannot read properties of undefined (reading ‘prototype‘)