自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

HarmonyOSAPP組件分享(二)

系統(tǒng) OpenHarmony
文章由鴻蒙社區(qū)產出,想要了解更多內容請前往:51CTO和華為官方戰(zhàn)略合作共建的鴻蒙技術社區(qū)https://harmonyos.51cto.com

[[388212]]

想了解更多內容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術社區(qū)

https://harmonyos.51cto.com

Button組件介紹和應用體驗分享

Button組件是常用的交互類組件之一,本節(jié)將來聊聊Button組件的使用以及按照按鈕的形狀,按鈕可以分為:普通按鈕,橢圓按鈕,膠囊按鈕,圓形按鈕等的各種的樣式圖

顯示效果:

代碼如下:

布局中的代碼:

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <DirectionalLayout 
  3.     xmlns:ohos="http://schemas.huawei.com/res/ohos" 
  4.     ohos:height="match_parent" 
  5.     ohos:width="match_parent" 
  6.     ohos:orientation="vertical"
  7.  
  8.     <Button 
  9.         ohos:id="$+id:jltfbtn" 
  10.         ohos:height="match_content" 
  11.         ohos:width="match_content" 
  12.         ohos:background_element="#FF17D3EB" 
  13.         ohos:layout_alignment="horizontal_center" 
  14.         ohos:text="我是一個按鈕button" 
  15.         ohos:padding="20vp" 
  16.         ohos:top_margin="10px" 
  17.         ohos:text_color="#FFFFFF" 
  18.         ohos:text_size="50" 
  19.         /> 
  20.     <Text 
  21.         ohos:height="100px" 
  22.         ohos:width="300px" 
  23.         ohos:text_size="20fp" 
  24.         ohos:top_margin="40px" 
  25.         ohos:left_margin="400px" 
  26.         ohos:text="普通按鈕"/> 
  27.     <Button 
  28.         ohos:width="200vp" 
  29.         ohos:height="70vp" 
  30.         ohos:text_size="27fp" 
  31.         ohos:text="button" 
  32.         ohos:background_element="$graphic:jltfcolor_blue_element" 
  33.         ohos:top_margin="15px" 
  34.         ohos:left_margin="90vp" 
  35.         ohos:bottom_margin="15vp" 
  36.         ohos:right_padding="8vp" 
  37.         ohos:left_padding="8vp" 
  38.         /> 
  39.     <Text 
  40.         ohos:height="100px" 
  41.         ohos:width="300px" 
  42.         ohos:text_size="20fp" 
  43.         ohos:left_margin="400px" 
  44.         ohos:text="橢圓按鈕"/> 
  45.     <Button 
  46.         ohos:width="200vp" 
  47.         ohos:height="70vp" 
  48.         ohos:text_size="27fp" 
  49.         ohos:text="button" 
  50.         ohos:background_element="$graphic:jltfoval_button_element" 
  51.         ohos:bottom_margin="15vp" 
  52.         ohos:top_margin="15px" 
  53.         ohos:left_margin="90vp" 
  54.         ohos:right_padding="8vp" 
  55.         ohos:left_padding="8vp" 
  56.         /> 
  57.     <Text 
  58.         ohos:height="100px" 
  59.         ohos:width="300px" 
  60.         ohos:text_size="20fp" 
  61.         ohos:left_margin="400px" 
  62.         ohos:text="膠囊按鈕"/> 
  63.     <Button 
  64.         ohos:id="$+id:button" 
  65.         ohos:width="200vp" 
  66.         ohos:height="70vp" 
  67.         ohos:text_size="27fp" 
  68.         ohos:text="button" 
  69.         ohos:background_element="$graphic:jltfcapsule_button_element" 
  70.         ohos:left_margin="90vp" 
  71.         ohos:top_margin="15px" 
  72.         ohos:bottom_margin="15vp" 
  73.         ohos:right_padding="15vp" 
  74.         ohos:left_padding="15vp" 
  75.         /> 
  76.     <Text 
  77.         ohos:height="100px" 
  78.         ohos:width="300px" 
  79.         ohos:text_size="20fp" 
  80.         ohos:left_margin="400px" 
  81.         ohos:text="圓形按鈕"/> 
  82.     <Button 
  83.         ohos:id="$+id:button2" 
  84.         ohos:width="140vp" 
  85.         ohos:height="140vp" 
  86.         ohos:text_size="27fp" 
  87.         ohos:background_element="$graphic:jltfcircle_button_element" 
  88.         ohos:text="+" 
  89.         ohos:left_margin="110vp" 
  90.         ohos:bottom_margin="15vp" 
  91.         ohos:right_padding="15vp" 
  92.         ohos:left_padding="15vp" 
  93.         /> 
  94. </DirectionalLayout> 
Slice中的代碼:
 
  1. package com.example.jltftiyan.slice; 
  2.  
  3. import com.example.jltftiyan.ResourceTable; 
  4. import ohos.aafwk.ability.AbilitySlice; 
  5. import ohos.aafwk.content.Intent; 
  6. import ohos.agp.components.Button; 
  7.  
  8. public class MainAbilitySlice extends AbilitySlice { 
  9.     @Override 
  10.     public void onStart(Intent intent) { 
  11.         super.onStart(intent); 
  12.         super.setUIContent(ResourceTable.Layout_ability_main); 
  13.  
  14.         Button button = (Button) findComponentById(ResourceTable.Id_jltfbtn); 
  15.         button.setClickedListener(l -> { 
  16.             //更改Button組件的內容 
  17.             button.setText("我被點擊了~"); 
  18.         }); 
  19.     } 
  20.  
  21.     @Override 
  22.     public void onActive() { 
  23.         super.onActive(); 
  24.     } 
  25.  
  26.     @Override 
  27.     public void onForeground(Intent intent) { 
  28.         super.onForeground(intent); 
  29.     } 
graphic目錄下xml文件的代碼示例如下:
 
  1. jltfcolor_blue_element.xml 
  2.  
  3. <?xml version="1.0" encoding="utf-8"?> 
  4. <shape xmlns:ohos="http://schemas.huawei.com/res/ohos" 
  5.        ohos:shape="rectangle"
  6.     <solid 
  7.         ohos:color="#007CFD"/> 
  8. </shape> 
  9.  
  10. jltfoval_button_element.xml 
  11.  
  12. <?xml version="1.0" encoding="utf-8"?> 
  13. <shape xmlns:ohos="http://schemas.huawei.com/res/ohos" 
  14.        ohos:shape="oval"
  15.     <solid 
  16.         ohos:color="#007CFD"/> 
  17. </shape> 
  18.  
  19. jltfcapsule_button_element.xml 
  20.  
  21. <?xml version="1.0" encoding="utf-8"?> 
  22. <shape xmlns:ohos="http://schemas.huawei.com/res/ohos" 
  23.        ohos:shape="rectangle"
  24.     <corners 
  25.         ohos:radius="100"/> 
  26.     <solid 
  27.         ohos:color="#007CFD"/> 
  28. </shape> 
  29.  
  30. jltfcircle_button_element.xml 
  31.  
  32. <?xml version="1.0" encoding="utf-8"?> 
  33. <shape xmlns:ohos="http://schemas.huawei.com/res/ohos" 
  34.        ohos:shape="oval"
  35.     <solid 
  36.         ohos:color="#007CFD"/> 
  37. </shape> 

StackLayout布局練習與分享

StackLayout直接在屏幕上開辟出一塊空白的區(qū)域,添加到這個布局中的視圖都是以層疊的方式顯示,而它會把這些視圖默認放到這塊區(qū)域的左上角,第一個添加到布局中視圖顯示在最底層,最后一個被放在最頂層。上一層的視圖會覆蓋下一層的視圖。

自己可以通過修改寬高設置大小來控制位置的變換,后面會有更多新的內容呈現(xiàn)出來,這里就簡單的敲了個案例。

代碼如下:

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <StackLayout 
  3.     xmlns:ohos="http://schemas.huawei.com/res/ohos" 
  4.     ohos:id="$+id:stack_layout" 
  5.     ohos:height="match_parent" 
  6.     ohos:width="match_parent"
  7.  
  8.  
  9.     <Text 
  10.         ohos:id="$+id:text_blue" 
  11.         ohos:text_alignment="bottom|right" 
  12.         ohos:text_size="24fp" 
  13.         ohos:text="第四層" 
  14.         ohos:height="match_parent" 
  15.         ohos:width="match_parent" 
  16.         ohos:background_element="#3F56EA" /> 
  17.  
  18.  
  19.     <Text 
  20.         ohos:id="$+id:text_light_purple" 
  21.         ohos:text_alignment="bottom|right" 
  22.         ohos:text_size="24fp" 
  23.         ohos:text="第三層" 
  24.         ohos:height="300vp" 
  25.         ohos:width="match_parent" 
  26.         ohos:background_element="#00AAEE" /> 
  27.     <Text 
  28.         ohos:id="$+id:text_light_lianxi" 
  29.         ohos:text_alignment="bottom|horizontal_center" 
  30.         ohos:text_size="24fp" 
  31.         ohos:text="第二層" 
  32.         ohos:height="match_parent" 
  33.         ohos:width="150vp" 
  34.         ohos:background_element="#FF74FF8B" /> 
  35.  
  36.  
  37.     <Text 
  38.         ohos:id="$+id:text_orange" 
  39.         ohos:text_alignment="center" 
  40.         ohos:text_size="24fp" 
  41.         ohos:text="第一層" 
  42.         ohos:height="80vp" 
  43.         ohos:width="match_parent" 
  44.         ohos:background_element="#00BFC9" /> 
  45.  
  46. </StackLayout> 
  47.  
  48.   

想了解更多內容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術社區(qū)

https://harmonyos.51cto.com

 

責任編輯:jianghua 來源: 鴻蒙社區(qū)
相關推薦

2021-03-22 09:48:32

鴻蒙HarmonyOS應用開發(fā)

2021-03-17 09:35:09

鴻蒙HarmonyOS應用開發(fā)

2021-03-30 09:45:07

鴻蒙HarmonyOS應用開發(fā)

2021-03-31 15:49:34

鴻蒙HarmonyOS應用

2021-03-26 09:35:35

鴻蒙HarmonyOS應用開發(fā)

2010-07-28 12:41:18

Flex組件

2017-01-19 18:58:11

iOS組件化方案

2011-03-31 13:52:22

Java

2012-11-12 09:41:31

Scrum敏捷開發(fā)開發(fā)培訓

2021-10-14 15:14:36

鴻蒙HarmonyOS應用

2012-04-28 21:25:58

APP

2011-07-13 16:48:55

CC++

2021-09-07 09:53:45

鴻蒙HarmonyOS應用

2023-04-02 10:06:24

組件vue3sign2.

2010-08-06 11:19:24

FlexPaperFlex

2022-02-17 20:07:45

Flex鴻蒙Flex組件

2009-12-16 10:49:42

Ruby操作二進制文件

2012-11-07 10:01:52

組件技術OAuth授權登陸

2012-11-07 10:09:11

組件技術OAuth授權登陸

2021-08-02 14:54:50

鴻蒙HarmonyOS應用
點贊
收藏

51CTO技術棧公眾號