鴻蒙HarmonyOS北向應用開發(fā)者 極速入門教程(一)續(xù)-實戰(zhàn)練習篇2
https://harmonyos.51cto.com/#zz
Tablet 模擬器上的代碼案例
新建項目選擇模板進行下一步。

顯示效果:

點擊“點擊了解更多”進入下一個頁面

代碼如下
第一個頁面的布局
- <?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
- ohos:width="match_parent"
- ohos:weight="1">
- <Text
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:text="蛟龍騰飛"
- ohos:text_size="40fp"
- ohos:top_margin="180px"
- ohos:left_margin="80px"/>
- </DirectionalLayout>
- <DirectionalLayout
- ohos:width="match_parent"
- ohos:weight="4"
- ohos:orientation="horizontal">
- <DirectionalLayout
- ohos:height="match_parent"
- ohos:weight="1">
- <Image
- ohos:width="600px"
- ohos:height="600px"
- ohos:top_margin="160px"
- ohos:left_margin="100px"
- ohos:image_src="$media:index6"/>
- </DirectionalLayout>
- <DirectionalLayout
- ohos:height="match_parent"
- ohos:weight="2">
- <Text
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:multiple_lines="true"
- ohos:text="帶你從傳統(tǒng)的互聯(lián)網(wǎng)、移動互聯(lián)網(wǎng)時代
- 跳轉(zhuǎn)到萬物互聯(lián)的智能世界!
- 馬上創(chuàng)建體驗個人、公司或組織的鴻蒙應用吧!"
- ohos:text_size="35fp"
- ohos:top_margin="240px"
- ohos:left_margin="60px"/>
- <Button
- ohos:id="$+id:jltfbutton"
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:text="點擊了解更多"
- ohos:text_size="40fp"
- ohos:top_margin="380px"
- ohos:left_margin="1000px"
- ohos:text_color="red"/>
- </DirectionalLayout>
- </DirectionalLayout>
- </DirectionalLayout>
第二個頁面的布局
- <?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
- ohos:width="match_parent"
- ohos:weight="1"
- >
- <Text
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:text="蛟龍騰飛"
- ohos:text_size="40fp"
- ohos:top_margin="180px"
- ohos:left_margin="80px"/>
- </DirectionalLayout>
- <DirectionalLayout
- ohos:width="match_parent"
- ohos:weight="4"
- ohos:orientation="horizontal">
- <DirectionalLayout
- ohos:height="match_parent"
- ohos:weight="1">
- <Image
- ohos:width="600px"
- ohos:height="600px"
- ohos:top_margin="60px"
- ohos:left_margin="100px"
- ohos:image_src="$media:index7"/>
- </DirectionalLayout>
- <DirectionalLayout
- ohos:height="match_parent"
- ohos:weight="2">
- <Text
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:multiple_lines="true"
- ohos:text="你好,歡迎來到鴻蒙時代!
- 蛟龍騰飛,鴻蒙先行者,全心全意為你提供鴻蒙各項服務!"
- ohos:text_size="35fp"
- ohos:top_margin="240px"
- ohos:left_margin="10px"/>
- </DirectionalLayout>
- </DirectionalLayout>
- </DirectionalLayout>
然后再第一個頁面中添加點擊事件進行跳轉(zhuǎn)
- Button button = (Button) findComponentById(ResourceTable.Id_jltfbutton);
- button.setClickedListener(new Component.ClickedListener() {
- @Override
- public void onClick(Component component) {
- present(new jltftabletSlice(),new Intent());
- }
- });
Lite wearable模擬器上的代碼案例
新建項目選擇模板進行下一步。

顯示效果:

點擊“點擊了解更多”進入下一個頁面

代碼如下:
Index.hml
- <div class="container">
- <text class="jltftxt">
- 蛟龍騰飛
- </text>
- <image src="/common/index22.jpg" class="jltfimg"/>
- <text class="jltftxt1">
- 帶你從傳統(tǒng)的互聯(lián)網(wǎng)、移動互
- </text>
- <text class="jltftxt2">
- 聯(lián)網(wǎng)時代. 跳轉(zhuǎn)到萬物互聯(lián)的智
- </text>
- <text class="jltftxt3">
- 能世界!。馬上創(chuàng)建體驗個人、
- </text>
- <text class="jltftxt4">
- 公司或組織的鴻蒙應用吧!
- </text>
- <input class="jltfbtn"type="button" value="點擊了解更多" onclick="jltfclick"/>
- </div>
Index.css
- .container {
- flex-direction: column;
- width: 454px;
- height: 454px;
- justify-content: center;
- align-items: center;
- }
- .jltftxt {
- margin-left: -180px;
- margin-bottom: 10px;
- }
- .jltftxt1 {
- width: 400px;
- font-size: 30px;
- }
- .jltfimg {
- width: 138px;
- height:103px;
- margin-left: 5px;
- }
- .jltfbtn {
- width: 200px;
- margin-bottom: -70px;
- }
Index.js
- import router from '@system.router'
- export default {
- data: {
- },
- jltfclick() {
- router.replace({
- uri:'pages/jltfindex/jltfindex'
- });
- }
- }
Jltfindex.hml
- <div class="container">
- <text class="jltftxt">
- 蛟龍騰飛
- </text>
- <image src="/common/index16.jpg" class="jltfimg"/>
- <text class="jltftxt1">
- 你好,歡迎來到鴻蒙時代!
- </text>
- <text class="jltftxt2">
- 蛟龍騰飛,鴻蒙先行者,全心全
- </text>
- <text class="jltftxt3">
- 意為你提供鴻蒙各項服務!
- </div>
Jltfindex.css
- .container {
- flex-direction: column;
- width: 454px;
- height: 454px;
- justify-content: center;
- align-items: center;
- }
- .jltftxt {
- margin-left: -180px;
- margin-bottom: 10px;
- }
- .jltftxt1 {
- width: 400px;
- font-size: 30px;
- }
- .jltfimg {
- width: 413px;
- height:103px;
- margin-left: 8px;
- }
- .jltfbtn {
- width: 200px;
- margin-bottom: -70px;
- }
Jltfindex.js
- export default {
- data: {
- }
- }
在第一個頁面中添加跳轉(zhuǎn)的代碼
在第一個頁面js文件中加入如下代碼即可
- jltfclick() {
- router.replace({
- uri:'pages/jltfindex/jltfindex'
- });
- }
2. 練習題二
還是基于“練習一”題目中的圖片和文字內(nèi)容,7種設備中用其他不同的模板樣式嘗試實現(xiàn)一下和“練習一”模板樣式不一樣的效果,盡可能每種設備實現(xiàn)一種不同的布局和效果呈現(xiàn),作業(yè)要求,樣式截圖與全部代碼。
3. 點擊和嘗試DevEco Studio里的每個菜單欄,概覽這個DevEco Studio的各項功能結(jié)構(gòu)。結(jié)合前面的練習,寫一個100字以上的Deveco Studio體驗心得。
具體編輯器使用的細節(jié)可以參考如下鏈接和內(nèi)容。
https://developer.harmonyos.com/cn/docs/documentation/doc-guides/tools_overview-0000001053582387

深圳市蛟龍騰飛網(wǎng)絡科技有限公司
©著作權歸作者和HarmonyOS技術社區(qū)共同所有,如需轉(zhuǎn)載,請注明出處,否則將追究法律責任
https://harmonyos.51cto.com/#zz