鸿蒙 UI控件分为Component 和 ComponentContainer,类似Android里面的View和ViewGroup
- Component:是界面中所有组件的基类,如 Text、Image 等
- ComponentContainer:标准布局功能的容器的基类。如 DirectionalLayout、DependentLayout 等。DirectionalLayout类似Android的LinearLayout,DependentLayout类似Android的RelativeLayout
另外鸿蒙大小单位有三种px、fp、vp
px:像素
vp:以屏幕相对像素为单位,也就是安卓中的dp
fp:相当于sp
控件API
命名:$+id:
match_content等价于Android wrop_parent
match_parent与Android一致
text 与Android一致
text_size 与Android一致
text_color 与Android一致
padding 与Android一致
top_margin 等价于Android margin_top
background_element 等价于Android的background
其他API后续再补充。
页面布局
DirectionalLayout
DirectionalLayout 的排列方向(orientation)分为水平(horizontal)或者垂直(vertical) 方向。使用 orientation 设置布局内组件的排列方式,默认为垂直排列,与LinearLayout一致,其他api有细微差别。
1.layout_alignment:
DependentLayout
相对布局,与RelativeLayout类似,具体API如下:
控制控件位置API