HarmonyOS APP组件分享(五)

系统 OpenHarmony
文章由鸿蒙社区产出,想要了解更多内容请前往:51CTO和华为官方战略合作共建的鸿蒙技术社区https://harmonyos.51cto.com

想了解更多内容,请访问:

51CTO和华为官方合作共建的鸿蒙技术社区

https://harmonyos.51cto.com 

HarmonyOS APP - ScrollView体验与分享

ScrollView是一种带滚动功能的组件,它采用滑动的方式在有限的区域内显示更多的内容。

这里我做了一个小案例,在ScrollView里面套ScrollView,当然我们也可以使用DirectionalLayout中的horizontal或者vertical属性控制图片滑动的方向这里使用ScrollView可以很方便的展示跟多的内容。

 

代码如下:

  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.     <DirectionalLayout 
  8.         ohos:height="1800px" 
  9.         ohos:width="match_parent" 
  10.         ohos:orientation="vertical"
  11.         <ScrollView 
  12.             ohos:height="match_parent" 
  13.             ohos:width="match_parent"
  14.             <DirectionalLayout 
  15.                 ohos:height="match_content" 
  16.                 ohos:width="match_parent" 
  17.                 ohos:orientation="vertical"
  18.                 <DirectionalLayout 
  19.                     ohos:height="match_content" 
  20.                     ohos:width="match_parent"
  21.                     <Image 
  22.                         ohos:height="600px" 
  23.                         ohos:width="match_parent" 
  24.                         ohos:image_src="$media:tupian1" 
  25.                         /> 
  26.                 </DirectionalLayout> 
  27.                 <DirectionalLayout 
  28.                     ohos:height="80px" 
  29.                     ohos:width="match_parent"
  30.                     <Text 
  31.                         ohos:height="match_parent" 
  32.                         ohos:width="match_parent" 
  33.                         ohos:text="颜色展示" 
  34.                         ohos:text_size="18fp"/> 
  35.                 </DirectionalLayout> 
  36.                 <DirectionalLayout 
  37.                     ohos:height="700px" 
  38.                     ohos:width="match_parent" 
  39.                     ohos:orientation="vertical"
  40.                     <ScrollView 
  41.                         ohos:height="match_parent" 
  42.                         ohos:width="match_parent"
  43.                         <DirectionalLayout 
  44.                             ohos:height="match_content" 
  45.                             ohos:width="match_parent" 
  46.                             ohos:orientation="vertical"
  47.                             <DirectionalLayout 
  48.                                 ohos:height="match_content" 
  49.                                 ohos:width="match_parent" 
  50.                                 ohos:orientation="vertical"
  51.                                 <Text 
  52.                                     ohos:height="80px" 
  53.                                     ohos:width="match_parent" 
  54.                                     ohos:text="红色" 
  55.                                     ohos:text_size="18fp"/> 
  56.                                 <Image 
  57.                                     ohos:height="match_content" 
  58.                                     ohos:width="match_parent" 
  59.                                     ohos:image_src="$media:red" 
  60.                                     /> 
  61.                             </DirectionalLayout> 
  62.                             <DirectionalLayout 
  63.                                 ohos:height="match_content" 
  64.                                 ohos:width="match_parent" 
  65.                                 ohos:orientation="vertical"
  66.                                 <Text 
  67.                                     ohos:height="80px" 
  68.                                     ohos:width="match_parent" 
  69.                                     ohos:text="蓝色" 
  70.                                     ohos:text_size="18fp"/> 
  71.                                 <Image 
  72.                                     ohos:height="match_content" 
  73.                                     ohos:width="match_parent" 
  74.                                     ohos:image_src="$media:blue" 
  75.                                     /> 
  76.                             </DirectionalLayout> 
  77.                             <DirectionalLayout 
  78.                                 ohos:height="match_content" 
  79.                                 ohos:width="match_parent" 
  80.                                 ohos:orientation="vertical"
  81.                                 <Text 
  82.                                     ohos:height="80px" 
  83.                                     ohos:width="match_parent" 
  84.                                     ohos:text="黄色" 
  85.                                     ohos:text_size="18fp"/> 
  86.                                 <Image 
  87.                                     ohos:height="match_content" 
  88.                                     ohos:width="match_parent" 
  89.                                     ohos:image_src="$media:yellow" 
  90.                                     /> 
  91.                             </DirectionalLayout> 
  92.                             <DirectionalLayout 
  93.                                 ohos:height="match_content" 
  94.                                 ohos:width="match_parent" 
  95.                                 ohos:orientation="vertical"
  96.                                 <Text 
  97.                                     ohos:height="80px" 
  98.                                     ohos:width="match_parent" 
  99.                                     ohos:text="粉色" 
  100.                                     ohos:text_size="18fp"/> 
  101.                                 <Image 
  102.                                     ohos:height="match_content" 
  103.                                     ohos:width="match_parent" 
  104.                                     ohos:image_src="$media:pink" 
  105.                                     /> 
  106.                             </DirectionalLayout> 
  107.                             <DirectionalLayout 
  108.                                 ohos:height="match_content" 
  109.                                 ohos:width="match_parent" 
  110.                                 ohos:orientation="vertical"
  111.                                 <Text 
  112.                                     ohos:height="80px" 
  113.                                     ohos:width="match_parent" 
  114.                                     ohos:text="绿色" 
  115.                                     ohos:text_size="18fp"/> 
  116.                                 <Image 
  117.                                     ohos:height="match_content" 
  118.                                     ohos:width="match_parent" 
  119.                                     ohos:image_src="$media:grenn" 
  120.                                     /> 
  121.                             </DirectionalLayout> 
  122.  
  123.                         </DirectionalLayout> 
  124.                     </ScrollView> 
  125.                 </DirectionalLayout> 
  126.                 <DirectionalLayout 
  127.                     ohos:height="80px" 
  128.                     ohos:width="match_parent"
  129.                     <Text 
  130.                         ohos:height="match_parent" 
  131.                         ohos:width="match_parent" 
  132.                         ohos:text="图片展示" 
  133.                         ohos:text_size="18fp"/> 
  134.                 </DirectionalLayout> 
  135.                 <DirectionalLayout 
  136.                     ohos:height="500px" 
  137.                     ohos:width="match_parent" 
  138.                     ohos:orientation="vertical"
  139.                     <ScrollView 
  140.                         ohos:height="match_parent" 
  141.                         ohos:width="match_parent"
  142.                         <DirectionalLayout 
  143.                             ohos:height="match_content" 
  144.                             ohos:width="match_parent" 
  145.                             ohos:orientation="vertical"
  146.                             <Image 
  147.                                 ohos:height="match_parent" 
  148.                                 ohos:width="match_parent" 
  149.                                 ohos:image_src="$media:fengjing"/> 
  150.                             <Image 
  151.                                 ohos:height="match_parent" 
  152.                                 ohos:width="match_parent" 
  153.                                 ohos:image_src="$media:mao"/> 
  154.                             <Image 
  155.                                 ohos:height="match_parent" 
  156.                                 ohos:width="match_parent" 
  157.                                 ohos:image_src="$media:gou"/> 
  158.                         </DirectionalLayout> 
  159.                     </ScrollView> 
  160.                 </DirectionalLayout> 
  161.             </DirectionalLayout> 
  162.         </ScrollView> 
  163.     </DirectionalLayout> 
  164. </DirectionalLayout> 

代码如下:

  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.     <DirectionalLayout 
  8.         ohos:height="1800px" 
  9.         ohos:width="match_parent" 
  10.         ohos:orientation="vertical"
  11.         <ScrollView 
  12.             ohos:height="match_parent" 
  13.             ohos:width="match_parent"
  14.             <DirectionalLayout 
  15.                 ohos:height="match_content" 
  16.                 ohos:width="match_parent" 
  17.                 ohos:orientation="vertical"
  18.                 <DirectionalLayout 
  19.                     ohos:height="match_content" 
  20.                     ohos:width="match_parent"
  21.                     <Image 
  22.                         ohos:height="600px" 
  23.                         ohos:width="match_parent" 
  24.                         ohos:image_src="$media:tupian1" 
  25.                         /> 
  26.                 </DirectionalLayout> 
  27.                 <DirectionalLayout 
  28.                     ohos:height="80px" 
  29.                     ohos:width="match_parent"
  30.                     <Text 
  31.                         ohos:height="match_parent" 
  32.                         ohos:width="match_parent" 
  33.                         ohos:text="颜色展示" 
  34.                         ohos:text_size="18fp"/> 
  35.                 </DirectionalLayout> 
  36.                 <DirectionalLayout 
  37.                     ohos:height="700px" 
  38.                     ohos:width="match_parent" 
  39.                     ohos:orientation="vertical"
  40.                     <ScrollView 
  41.                         ohos:height="match_parent" 
  42.                         ohos:width="match_parent"
  43.                         <DirectionalLayout 
  44.                             ohos:height="match_content" 
  45.                             ohos:width="match_parent" 
  46.                             ohos:orientation="vertical"
  47.                             <DirectionalLayout 
  48.                                 ohos:height="match_content" 
  49.                                 ohos:width="match_parent" 
  50.                                 ohos:orientation="vertical"
  51.                                 <Text 
  52.                                     ohos:height="80px" 
  53.                                     ohos:width="match_parent" 
  54.                                     ohos:text="红色" 
  55.                                     ohos:text_size="18fp"/> 
  56.                                 <Image 
  57.                                     ohos:height="match_content" 
  58.                                     ohos:width="match_parent" 
  59.                                     ohos:image_src="$media:red" 
  60.                                     /> 
  61.                             </DirectionalLayout> 
  62.                             <DirectionalLayout 
  63.                                 ohos:height="match_content" 
  64.                                 ohos:width="match_parent" 
  65.                                 ohos:orientation="vertical"
  66.                                 <Text 
  67.                                     ohos:height="80px" 
  68.                                     ohos:width="match_parent" 
  69.                                     ohos:text="蓝色" 
  70.                                     ohos:text_size="18fp"/> 
  71.                                 <Image 
  72.                                     ohos:height="match_content" 
  73.                                     ohos:width="match_parent" 
  74.                                     ohos:image_src="$media:blue" 
  75.                                     /> 
  76.                             </DirectionalLayout> 
  77.                             <DirectionalLayout 
  78.                                 ohos:height="match_content" 
  79.                                 ohos:width="match_parent" 
  80.                                 ohos:orientation="vertical"
  81.                                 <Text 
  82.                                     ohos:height="80px" 
  83.                                     ohos:width="match_parent" 
  84.                                     ohos:text="黄色" 
  85.                                     ohos:text_size="18fp"/> 
  86.                                 <Image 
  87.                                     ohos:height="match_content" 
  88.                                     ohos:width="match_parent" 
  89.                                     ohos:image_src="$media:yellow" 
  90.                                     /> 
  91.                             </DirectionalLayout> 
  92.                             <DirectionalLayout 
  93.                                 ohos:height="match_content" 
  94.                                 ohos:width="match_parent" 
  95.                                 ohos:orientation="vertical"
  96.                                 <Text 
  97.                                     ohos:height="80px" 
  98.                                     ohos:width="match_parent" 
  99.                                     ohos:text="粉色" 
  100.                                     ohos:text_size="18fp"/> 
  101.                                 <Image 
  102.                                     ohos:height="match_content" 
  103.                                     ohos:width="match_parent" 
  104.                                     ohos:image_src="$media:pink" 
  105.                                     /> 
  106.                             </DirectionalLayout> 
  107.                             <DirectionalLayout 
  108.                                 ohos:height="match_content" 
  109.                                 ohos:width="match_parent" 
  110.                                 ohos:orientation="vertical"
  111.                                 <Text 
  112.                                     ohos:height="80px" 
  113.                                     ohos:width="match_parent" 
  114.                                     ohos:text="绿色" 
  115.                                     ohos:text_size="18fp"/> 
  116.                                 <Image 
  117.                                     ohos:height="match_content" 
  118.                                     ohos:width="match_parent" 
  119.                                     ohos:image_src="$media:grenn" 
  120.                                     /> 
  121.                             </DirectionalLayout> 

  1.                   </DirectionalLayout> 
  2.                 </ScrollView> 
  3.             </DirectionalLayout> 
  4.             <DirectionalLayout 
  5.                 ohos:height="80px" 
  6.                 ohos:width="match_parent"
  7.                 <Text 
  8.                     ohos:height="match_parent" 
  9.                     ohos:width="match_parent" 
  10.                     ohos:text="图片展示" 
  11.                     ohos:text_size="18fp"/> 
  12.             </DirectionalLayout> 
  13.             <DirectionalLayout 
  14.                 ohos:height="500px" 
  15.                 ohos:width="match_parent" 
  16.                 ohos:orientation="vertical"
  17.                 <ScrollView 
  18.                     ohos:height="match_parent" 
  19.                     ohos:width="match_parent"
  20.                     <DirectionalLayout 
  21.                         ohos:height="match_content" 
  22.                         ohos:width="match_parent" 
  23.                         ohos:orientation="vertical"
  24.                         <Image 
  25.                             ohos:height="match_parent" 
  26.                             ohos:width="match_parent" 
  27.                             ohos:image_src="$media:fengjing"/> 
  28.                         <Image 
  29.                             ohos:height="match_parent" 
  30.                             ohos:width="match_parent" 
  31.                             ohos:image_src="$media:mao"/> 
  32.                         <Image 
  33.                             ohos:height="match_parent" 
  34.                             ohos:width="match_parent" 
  35.                             ohos:image_src="$media:gou"/> 
  36.                     </DirectionalLayout> 
  37.                 </ScrollView> 
  38.             </DirectionalLayout> 
  39.         </DirectionalLayout> 
  40.     </ScrollView> 
  41. </DirectionalLayout> 
  42. rectionalLayout> 

完整代码地址:

https://gitee.com/jltfcloudcn/jump_to/tree/master/jltf_ScrollView_component

HarmonyOS APP - Checkbox体验与分享

显示效果:

点击下面的选项

布局中的代码:

  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.     ohos:left_padding="40px" 
  8.     ohos:top_padding="40vp"
  9.  
  10.  
  11.     <DirectionalLayout 
  12.         ohos:height="match_content" 
  13.         ohos:width="match_parent" 
  14.         ohos:orientation="vertical"
  15.  
  16.  
  17.         <Text 
  18.             ohos:height="match_content" 
  19.             ohos:width="match_content" 
  20.             ohos:text_size="18fp" 
  21.             ohos:text="下面哪个是水果?(多选)"/> 
  22.  
  23.  
  24.         <Text 
  25.             ohos:id="$+id:jltftext_answer" 
  26.             ohos:height="match_content" 
  27.             ohos:width="match_content" 
  28.             ohos:left_margin="20vp" 
  29.             ohos:text_size="20fp" 
  30.             ohos:text_color="#FF3333" 
  31.             ohos:text="[]" /> 
  32.     </DirectionalLayout> 
  33.  
  34.  
  35.     <Checkbox 
  36.         ohos:id="$+id:jltfcheck_box_1" 
  37.         ohos:top_margin="40vp" 
  38.         ohos:height="match_content" 
  39.         ohos:width="match_content" 
  40.         ohos:text="A 苹果" 
  41.         ohos:text_size="20fp" 
  42.         ohos:text_color_on="#FF3333" 
  43.         ohos:text_color_off="#000000"/> 
  44.  
  45.  
  46.     <Checkbox 
  47.         ohos:id="$+id:jltfcheck_box_2" 
  48.         ohos:top_margin="40vp" 
  49.         ohos:height="match_content" 
  50.         ohos:width="match_content" 
  51.         ohos:text="B 香蕉" 
  52.         ohos:text_size="20fp" 
  53.         ohos:text_color_on="#FF3333" 
  54.         ohos:text_color_off="#000000"/> 
  55.  
  56.  
  57.     <Checkbox 
  58.         ohos:id="$+id:jltfcheck_box_3" 
  59.         ohos:top_margin="40vp" 
  60.         ohos:height="match_content" 
  61.         ohos:width="match_content" 
  62.         ohos:text="C 草莓" 
  63.         ohos:text_size="20fp" 
  64.         ohos:text_color_on="#FF3333" 
  65.         ohos:text_color_off="#000000" /> 
  66.  
  67.  
  68.     <Checkbox 
  69.         ohos:id="$+id:jltfcheck_box_4" 
  70.         ohos:top_margin="40vp" 
  71.         ohos:height="match_content" 
  72.         ohos:width="match_content" 
  73.         ohos:text="D 土豆" 
  74.         ohos:text_size="20fp" 
  75.         ohos:text_color_on="#FF3333" 
  76.         ohos:text_color_off="black" /> 
  77. </DirectionalLayout> 

完整代码地址:

https://gitee.com/jltfcloudcn/jump_to/tree/master/jltf_checkbox_component

想了解更多内容,请访问:

51CTO和华为官方合作共建的鸿蒙技术社区

https://harmonyos.51cto.com

 

责任编辑:jianghua 来源: 鸿蒙社区
相关推荐

2021-03-17 09:35:09

鸿蒙HarmonyOS应用开发

2021-03-26 09:35:35

鸿蒙HarmonyOS应用开发

2021-03-31 15:49:34

鸿蒙HarmonyOS应用

2022-02-10 15:14:50

HarmonyOS操作系统鸿蒙

2021-08-12 14:59:15

鸿蒙HarmonyOS应用

2021-01-11 11:36:23

鸿蒙HarmonyOSApp开发

2021-06-01 14:32:44

鸿蒙HarmonyOS应用

2021-06-22 09:44:56

鸿蒙HarmonyOS应用

2021-10-26 15:22:52

鸿蒙HarmonyOS应用

2021-08-26 15:28:05

鸿蒙HarmonyOS应用

2021-11-01 10:21:36

鸿蒙HarmonyOS应用

2021-03-18 09:36:02

鸿蒙HarmonyOS应用

2022-05-19 15:59:23

组件焦点鸿蒙

2022-04-24 15:17:56

鸿蒙操作系统

2021-03-22 09:48:32

鸿蒙HarmonyOS应用开发

2012-04-28 21:25:58

APP

2022-07-06 20:24:08

ArkUI计时组件

2021-07-23 08:57:32

鸿蒙HarmonyOS应用

2021-10-14 15:14:36

鸿蒙HarmonyOS应用

2021-08-05 09:49:44

鸿蒙HarmonyOS应用
点赞
收藏

51CTO技术栈公众号