新聞中心
想了解更多內(nèi)容,請(qǐng)?jiān)L問:

和華為官方合作共建的鴻蒙技術(shù)社區(qū)
https://harmonyos./#zz
三、實(shí)戰(zhàn)練習(xí)
截圖另外做文檔答題。文檔要求,文件名:某某研究日志日期。文件內(nèi)容,題目和答題,截圖代碼和文字等綜合展示。
1.練習(xí)題一
以下是基于DevEco Studio蛟龍騰飛北向應(yīng)用開發(fā)工程師已經(jīng)實(shí)現(xiàn)的布局、功能、代碼及路徑,請(qǐng)安裝要求一模一樣的流程和效果,在自己的DevEco Studio實(shí)現(xiàn)。這里我們可以自行選擇自己想開發(fā)的設(shè)備和模板,這里我們以Phone為例,開發(fā)模板選擇空特性java的開發(fā)模板,點(diǎn)擊next進(jìn)行下一步。
開發(fā)的設(shè)備有七種:
- Phone
- Tablet
- Car
- Tv
- Wearable
- Lite wearable
- smart vision
Phone設(shè)備中有很多種不同的模板,主要是java和js進(jìn)行開發(fā)以及不同的模板樣式,不同樣式之間布局不一樣,不同的布局所展示的效果代碼已經(jīng)寫入其中,只需要加入想加入的元素即可。
選擇好了之后點(diǎn)擊next進(jìn)行下一步。
這里是創(chuàng)建項(xiàng)目的一些項(xiàng)目配置,配置完成點(diǎn)擊Finish完成創(chuàng)建。
完成創(chuàng)建后,我們進(jìn)入了主界面,這里需要等待一小會(huì),因?yàn)橐恍┡渲脰|西在進(jìn)行下載配置。
Phone模擬器上的代碼案例:
顯示效果:
雙擊圖中選中的設(shè)備就可以運(yùn)行了。
顯示如下:
運(yùn)行效果:
點(diǎn)擊“點(diǎn)擊了解更多”進(jìn)入下一個(gè)頁(yè)面:
代碼如下:
第一個(gè)布局中
- xmlns:ohos="http://schemas.huawei.com/res/ohos"
- ohos:height="match_parent"
- ohos:width="match_parent"
- ohos:orientation="vertical">
- ohos:width="match_parent"
- ohos:weight="1">
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:text="蛟龍騰飛"
- ohos:text_size="80px"
- ohos:top_margin="280px"
- ohos:left_margin="50px"/>
- ohos:weight="1"
- ohos:width="match_parent">
- ohos:width="1080px"
- ohos:height="468px"
- ohos:image_src="$media:index12.jpg"/>
- ohos:width="match_parent"
- ohos:weight="3">
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:text_size="60px"
- ohos:multiple_lines="true"
- ohos:left_margin="8px"
- ohos:text="帶你從傳統(tǒng)的互聯(lián)網(wǎng)、移動(dòng)互聯(lián)網(wǎng)時(shí)代"/>
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:text_size="60px"
- ohos:multiple_lines="true"
- ohos:left_margin="8px"
- ohos:top_margin="10px"
- ohos:text="跳轉(zhuǎn)到萬(wàn)物互聯(lián)的智能世界!"/>
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:text_size="60px"
- ohos:multiple_lines="true"
- ohos:left_margin="8px"
- ohos:top_margin="10px"
- ohos:text="馬上創(chuàng)建體驗(yàn)個(gè)人、公司或組織的鴻蒙應(yīng)用吧!"/>
第二個(gè)布局中
- xmlns:ohos="http://schemas.huawei.com/res/ohos"
- ohos:height="match_parent"
- ohos:width="match_parent"
- ohos:orientation="vertical">
- ohos:width="match_parent"
- ohos:weight="1">
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:text="蛟龍騰飛"
- ohos:text_size="80px"
- ohos:top_margin="280px"
- ohos:left_margin="50px"/>
- ohos:weight="1"
- ohos:width="match_parent">
- ohos:width="1080px"
- ohos:height="468px"
- ohos:image_src="$media:index13.jpg"/>
- ohos:width="match_parent"
- ohos:weight="3">
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:text_size="60px"
- ohos:multiple_lines="true"
- ohos:left_margin="8px"
- ohos:text="你好,歡迎來(lái)到鴻蒙時(shí)代!"/>
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:text_size="60px"
- ohos:multiple_lines="true"
- ohos:left_margin="8px"
- ohos:top_margin="10px"
- ohos:text="蛟龍騰飛,鴻蒙先行者,全心全意為你"/>
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:text_size="60px"
- ohos:multiple_lines="true"
- ohos:left_margin="10px"
- ohos:top_margin="10px"
- ohos:text="提供鴻蒙各項(xiàng)服務(wù)! 馬上咨詢:李先生 13725519713 或 18138827525"/>
在slice文件的類中添加點(diǎn)擊事件進(jìn)行跳轉(zhuǎn):
- Button button = (Button) findComponentById(ResourceTable.Id_jltfbutton);
- button.setClickedListener(new Component.ClickedListener() {
- @Override
- public void onClick(Component component) {
- present(new JltfAbilitySlice(),new Intent());
- }
- });
TV模擬器上的代碼案例:
新建項(xiàng)目選擇模板進(jìn)行下一步。
顯示效果:
點(diǎn)擊“點(diǎn)擊了解更多”進(jìn)入下一個(gè)頁(yè)面。
代碼如下:
第一個(gè)頁(yè)面中的布局
- xmlns:ohos="http://schemas.huawei.com/res/ohos"
- ohos:height="match_parent"
- ohos:width="match_parent"
- ohos:orientation="vertical">
- ohos:width="match_parent"
- ohos:height="160px"
- >
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:text="蛟龍騰飛"
- ohos:text_size="25fp"
- ohos:top_margin="40px"
- ohos:left_margin="40px"/>
- ohos:width="match_parent"
- ohos:height="920px"
- ohos:orientation="horizontal">
- ohos:height="match_parent"
- ohos:width="820px">
- ohos:width="600px"
- ohos:height="600px"
- ohos:top_margin="60px"
- ohos:left_margin="100px"
- ohos:image_src="$media:index6"/>
- ohos:height="match_parent"
- ohos:width="1100px">
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:multiple_lines="true"
- ohos:text="帶你從傳統(tǒng)的互聯(lián)網(wǎng)、移動(dòng)互聯(lián)網(wǎng)時(shí)代
- 跳轉(zhuǎn)到萬(wàn)物互聯(lián)的智能世界!
- 馬上創(chuàng)建體驗(yàn)個(gè)人、公司或組織的鴻蒙應(yīng)用吧!"
- ohos:text_size="25fp"
- ohos:top_margin="240px"
- ohos:left_margin="10px"/>
第二個(gè)頁(yè)面中的布局
- xmlns:ohos="http://schemas.huawei.com/res/ohos"
- ohos:height="match_parent"
- ohos:width="match_parent"
- ohos:orientation="vertical">
- ohos:width="match_parent"
- ohos:height="160px"
- >
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:text="蛟龍騰飛"
- ohos:text_size="25fp"
- ohos:top_margin="40px"
- ohos:left_margin="40px"/>
- ohos:width="match_parent"
- ohos:height="920px"
- ohos:orientation="horizontal">
- ohos:id="$+id:direction1"
- ohos:height="match_parent"
- ohos:width="820px">
- ohos:width="600px"
- ohos:height="600px"
- ohos:top_margin="60px"
- ohos:left_margin="100px"
- ohos:image_src="$media:index7"/>
- ohos:height="match_parent"
- ohos:width="1100px">
- ohos:width="match_content"
- ohos:height="match_content"
- ohos:multiple_lines="true"
- ohos:text="你好,歡迎來(lái)到鴻蒙時(shí)代!
- 蛟龍騰飛,鴻蒙先行者,全心全意為你提供鴻蒙各項(xiàng)服務(wù)! 馬上咨詢:
- 李先生:13725519713 或 18138827525"
- ohos:text_size="25fp"
- ohos:top_margin="240px"
- ohos:left_margin="10px"/>
然后再第一個(gè)頁(yè)面中加入點(diǎn)擊事件進(jìn)行跳轉(zhuǎn)
- Button button = (Button) findComponentById(ResourceTable.Id_jltfbutton);
- button.setClickedListener(new Component.ClickedListener() {
- @Override
- public void onClick(Component component) {
- present(new JltfAbilitySlice(),new Intent());
- }
- });
Smart vision模擬器上的代碼案例
新建項(xiàng)目選擇模板進(jìn)行下一步。
這里選擇的是js開發(fā)的模板就需要下載node.js文件在編輯器中進(jìn)行配置(node.js)網(wǎng)上有下載教程。
顯示效果:
點(diǎn)擊“點(diǎn)擊了解更多”進(jìn)入下一個(gè)頁(yè)面
代碼如下:
Index.hml
- 蛟龍騰飛
- 帶你從傳統(tǒng)的互聯(lián)網(wǎng)、移動(dòng)互
- 聯(lián)網(wǎng)時(shí)代. 跳轉(zhuǎn)到萬(wàn)物互聯(lián)的智
- 能世界!。馬上創(chuàng)建體驗(yàn)個(gè)人、
- 公司或組織的鴻蒙應(yīng)用吧!
Index.css
- .container {
- flex-direction: column;
- width: 960px;
- height: 480px;
- justify-content: center;
- align-items: center;
- }
- .container1 {
- flex-direction: row;
- width: 960px;
- height: 400px;
- }
- .container2 {
- margin-left: 30px;
- flex-direction: column;
- width: 600px;
- height: 400px;
- }
- .jltftxt {
- margin-left: -700px;
- margin-bottom: 10px;
- font-size: 45px;
- }
- .jltftxt1 {
- margin-top: 45px;
- }
- .jltftxt4 {
- margin-left: 5px;
- }
- .jltfimg {
- margin-top: 40px;
- width: 300px;
- height: 282px;
- margin-left: 40px;
- }
- .jltfbtn {
- height: 60px;
- width: 280px;
- margin-left: 260px;
- margin-top: 50px;
- }
- .jltftxt1,.jltftxt2,.jltftxt3,.jltftxt4{
- font-size: 40px;
- margin-left: 20px;
- }
Index.js
- import router from '@system.router'
- export default {
- data: {
- },
- jltfclick() {
- router.replace({
- uri:'pages/jltfindex/jltfindex'
- });
- }
- }
- jltfIndex.hml
- 蛟龍騰飛
- 你好,歡迎來(lái)到鴻蒙時(shí)代!
- 蛟龍騰飛,鴻蒙先行者,全
- 心全意為你提供鴻蒙各項(xiàng)服
- 務(wù)!
jltfIndex.css
- .container {
- flex-direction: column;
- width: 960px;
- height: 480px;
- justify-content: center;
- align-items: center;
- }
- .container1 {
- flex-direction: row;
- width: 960px;
- height: 400px;
- }
- .container2 {
- margin-left: 5px;
- flex-direction: column;
- width: 600px;
- height: 400px;
- }
- .jltftxt {
- margin-left: -700px;
- margin-bottom: 10px;
- font-size: 45px;
- }
- .jltftxt1 {
- margin-top: 50px;
- }
- .jltfimg {
- margin-top: 20px;
- width: 357px;
- height: 321px;
- margin-left: 20px;
- }
- .jltftxt1,.jltftxt2,.jltftxt3,.jltftxt4{
- font-size: 45px;
- margin-left: 20px;
- }
jltfIndex.js
- export default {
- data: {
- }
- }
在第一個(gè)頁(yè)面js文件中加入跳轉(zhuǎn)的代碼
- jltfclick() {
- router.replace({
- uri:'pages/jltfindex/jltfindex'
- });
- }
還得在配置文件中配置相關(guān)下一個(gè)頁(yè)面的位置
config.json找到圖中js的位置
- "js": [
- {
- "pages": [
- "pages/index/index",
- "pages/jltfindex/jltfindex"
- ],
- "name": "default"
- }
- ]
加入"pages/jltfindex/jltfindex"下一個(gè)頁(yè)面位置即可
wearable模擬器上的代碼案例
新建項(xiàng)目選擇模板進(jìn)行下一步。
顯示效果:
點(diǎn)擊“點(diǎn)擊了解更多”進(jìn)入下一個(gè)頁(yè)面
代碼如下:
第一個(gè)頁(yè)面
- Index.hml
- 蛟龍騰飛
- 帶你從傳統(tǒng)的互聯(lián)網(wǎng)、移動(dòng)互
- 聯(lián)網(wǎng)時(shí)代. 跳轉(zhuǎn)到萬(wàn)物互聯(lián)的智
- 能世界!。馬上創(chuàng)建體驗(yàn)個(gè)人、
- 公司或組織的鴻蒙應(yīng)用吧!
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;
- }
- .jltftxt4 {
- margin-left: 5px;
- }
- .jltfimg {
- width: 138px;
- height: 103px;
- margin-left: 5px;
- }
- .jltfbtn {
- height: 60px;
- width: 280px;
- margin-bottom: -60px;
- }
- .jltftxt1,.jltftxt2,.jltftxt3,.jltftxt4{
- font-size: 30px;
- }
Index.js
- import router from '@system.router'
- export default {
- data: {
- },
- jltfclick() {
- router.replace({
- uri:'pages/jltfindex/jltfindex'
- });
- }
- }
Jltfidnex.hml
- 蛟龍騰飛
- 你好,歡迎來(lái)到鴻蒙時(shí)代!
- 蛟龍騰飛,鴻蒙先行者,全心全
- 意為你提供鴻蒙各項(xiàng)服務(wù)!
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;
- margin-left: 30px;
- }
- .jltfimg {
- width: 413px;
- height: 103px;
- margin-left: 8px;
- }
- .jltfbtn {
- width: 200px;
- margin-bottom: -70px;
- }
- .jltftxt1,.jltftxt2,.jltftxt3,.jltftxt4{
- font-size: 30px;
- }
Jltfindex.js
- export default {
- data: {
- }
- }
然后進(jìn)行頁(yè)面跳轉(zhuǎn)的配置
在一個(gè)頁(yè)面index.js中進(jìn)行配置
- jltfclick() {
- router.replace({
- uri:'pages/jltfindex/jltfindex'
- });
- }
這樣了還不能跳轉(zhuǎn),“wearable”和“l(fā)itewearable
本文名稱:鴻蒙HarmonyOS北向應(yīng)用開發(fā)者極速入門教程(一)續(xù)-實(shí)戰(zhàn)練習(xí)篇1
文章來(lái)源:http://www.5511xx.com/article/coceico.html


咨詢
建站咨詢
