撰寫我的第一個鴻蒙APP界面、
1、創建專案
如何創建專案,請參考這篇文章 ,鴻蒙開發|HAIWEI DevEco Studio 安裝配置 運行Hello World! (https://blog.csdn.net/weixin_56575519/article/details/117079223)
2、通過XML技術撰寫頁面
在java UI框架中,提供了兩種撰寫布局的方式:在XML中宣告UI布局和在代碼中創建布局,這兩種方式創建出來的布局沒有本質區別,為了熟悉兩種方式,我們通過XML撰寫第一個界面,通過代碼的方式撰寫第二個界面,
2、1創建新的專案,命名layout
(1)首先新建手表工程

在“project”視窗,打開“entry>src>main>resources>bace",右鍵base檔案夾,選擇新建>目錄>,命名為layout,

2、2創建xml布局檔案
右鍵點擊first檔案夾,選擇新建>檔案,命名為“main_layout.xml"


2、3打開新建XML檔案,并添加代碼
打開“main_layout.xml"檔案,添加一個文本和一個按鈕,示例代碼如下
<?xml version="1.0" encoding="utf-8" ?>
<Dependentfirst
xmlns:ohos="http:schemas.huawei.cn.com/res/ohos"
ohos:width="match_parent"
ohos:height="match_parent"
ohos:background_element="#000000">
<text
ohos:id="$+id:button"
ohos:width="manth_content"
ohos:height="match_content"
ohos:center_in_parent="true"
ohos:text="hello world"
ohos:text_color="white"
ohos:text_size="32fp"/>
<Button
ohos:id="$+id:button"
ohos:width="manth_content"
ohos:height="match_content"
ohos:text_size="19fp"
ohos:text="Next"
ohos:top_padding="8vp"
ohos:botton_padding="80vp"
ohos:left_padding="80vp"
ohos:text_color="white"
ohos:background_element="$graphic:button_element"
ohos:center_in_parent="true"
ohos:align_parent_botton="true"
</Dependentfirst>
2、4 創建按鈕XML
前面的按鈕背景是通過“button_element"來顯示的,需要在base目錄下創建graphic檔案夾在graphic檔案夾中創建一個”button_element.xml"檔案,
(1)和步驟23 步一樣,我們在graphic目錄下創建button的XML
(2)“button_element.xml"的示例代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:shape="oval">
<solid
ohos:color="#007DFF"/>
</shape>
3、運行專案
點擊工具之中的HvD Manager

然后點擊手表模擬器

最后點擊運行按鈕,就能得到我們創建的界面了,

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/286633.html
標籤:其他
