当前位置:主页 > 查看内容

HarmonyOS APP组件分享(一)

发布时间:2021-04-20 00:00| 位朋友查看

简介:想了解更多内容,请访问: 51CTO和华为官方战略合作共建的鸿蒙技术社区 https://harmonyos.51cto.com HarmonyOSAPP-Image体验与分享 一、各项效果展示 二、体验操作过程 这里敲的是一个image的案例 实现我们得导入一张图片,把这张图片导入到entry src main……

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

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

https://harmonyos.51cto.com

HarmonyOSAPP-Image体验与分享

一、各项效果展示

二、体验操作过程

这里敲的是一个image的案例

实现我们得导入一张图片,把这张图片导入到“entry > src > main > resources > base > media”中,如下图所示:

这里我们可以通过在布局里面使用Image标签进行图片的插入和样式的设置。

这里我们可以通过image_src导入想要的图片,这里要注意图片的规格和大小。

我们也可以通过alpha色泽图片的透明性

我们也可以通过scale_x,scale_y设置图片的缩放系数

我们这里也可以通过设置clip_alignment控制裁剪的位置

三、完整代码下载

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

HarmonyOSAPP-TextField体验与分享

TextField提供了一种文本输入框。下面会通过一个案例给大家展示一下这个组件。

显示效果:

代码如下:

  1. Slice文件中 
  2.  
  3. package com.example.jltftiyan3.slice; 
  4.  
  5. import com.example.jltftiyan3.ResourceTable; 
  6. import ohos.aafwk.ability.AbilitySlice; 
  7. import ohos.aafwk.content.Intent; 
  8. import ohos.agp.components.Button; 
  9. import ohos.agp.components.Component; 
  10. import ohos.agp.components.Text; 
  11. import ohos.agp.components.TextField; 
  12. import ohos.agp.components.element.ShapeElement; 
  13.  
  14. public class MainAbilitySlice extends AbilitySlice { 
  15.     @Override 
  16.     public void onStart(Intent intent) { 
  17.         super.onStart(intent); 
  18.         super.setUIContent(ResourceTable.Layout_ability_main); 
  19.  
  20.     } 
  21.  
  22.     @Override 
  23.     public void onActive() { 
  24.         super.onActive(); 
  25.     } 
  26.  
  27.     @Override 
  28.     public void onForeground(Intent intent) { 
  29.         super.onForeground(intent); 
  30.     } 

布局中的代码:

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <DirectionalLayout 
  3.     xmlns:ohos="http://schemas.huawei.com/res/ohos" 
  4.     ohos:width="match_parent" 
  5.     ohos:height="match_parent" 
  6.     ohos:background_element="#FFC9C3C3" 
  7.     ohos:orientation="vertical"
  8.  
  9.     <StackLayout 
  10.         ohos:top_margin="60vp" 
  11.         ohos:width="match_parent" 
  12.         ohos:height="match_content" 
  13.         ohos:layout_alignment="center"
  14.         <TextField 
  15.             ohos:id="$+id:name_textField" 
  16.             ohos:width="1000px" 
  17.             ohos:height="match_content" 
  18.             ohos:multiple_lines="false" 
  19.             ohos:left_padding="24vp" 
  20.             ohos:right_padding="24vp" 
  21.             ohos:top_padding="8vp" 
  22.             ohos:bottom_padding="8vp" 
  23.             ohos:min_height="44vp" 
  24.             ohos:text_size="18fp" 
  25.             ohos:layout_alignment="center" 
  26.             ohos:text_alignment="center_vertical" 
  27.             ohos:background_element="$graphic:jltfbackground_text_field" 
  28.             ohos:hint="请输入账号" /> 
  29.  
  30.     </StackLayout> 
  31.  
  32.     <TextField 
  33.         ohos:top_margin="40vp" 
  34.         ohos:id="$+id:password_text_field" 
  35.         ohos:width="1000px" 
  36.         ohos:height="match_content" 
  37.         ohos:multiple_lines="false" 
  38.         ohos:left_padding="24vp" 
  39.         ohos:right_padding="24vp" 
  40.         ohos:top_padding="8vp" 
  41.         ohos:bottom_padding="8vp" 
  42.         ohos:min_height="44vp" 
  43.         ohos:text_size="18fp" 
  44.         ohos:layout_alignment="center" 
  45.         ohos:text_alignment="center_vertical" 
  46.         ohos:background_element="$graphic:jltfbackground_text_field" 
  47.         ohos:hint="请输入密码" /> 
  48.  
  49.     <Button 
  50.         ohos:top_margin="40vp" 
  51.         ohos:id="$+id:ensure_button" 
  52.         ohos:width="120vp" 
  53.         ohos:height="35vp" 
  54.         ohos:background_element="$graphic:jltfbackground_btn" 
  55.         ohos:text="Log in" 
  56.         ohos:text_size="20fp" 
  57.         ohos:layout_alignment="horizontal_center"/> 
  58.  
  59. </DirectionalLayout> 

完整代码包地址:https://gitee.com/jltfcloudcn/jump_to/tree/master/jltf_TextField_component

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

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

https://harmonyos.51cto.com


本文转载自网络,原文链接:https://harmonyos.51cto.com/#zz
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!

推荐图文


随机推荐