【5年Android从零复盘系列之五】关于页面布局控件开发总结
16lz
2022-01-17
1.Android开发常用布局
- LinearLayout 【高频】
- RelativeLayout 【高频】
- FrameLayout 【较少】
- FlexboxLayout 【较少】
- ConstraintLayout 【中频】
AbsoluteLayout【极少】- TableLayout 【极少】
- GridLayout 【较少】
- NestedScrollView 【中频】
- HorizontalScrollView【较少】
- PercentRelativeLayout 【较少】使用全解->
- PercentFrameLayout【较少】使用全解->
- PercentLinearlayout 【较少】鸿洋大神github ->
2.开发注意细节
2.1 LinearLayout
android:layout_widthandroid:layout_height是必须属性,子View在使用layout_weight时,子View最好将对应方向的android:layout_width或android:layout_height 值设置为0dpandroid:orientation布局方向是必须属性,默认水平方向,建议单子View时也显式设置方向
2.2 RelativeLayout
~~layout_alignParentLeft~~ : 与父布局左对齐,建议使用layout_alignParentStartlayout_alignParentTop : 与父布局上对齐~~layout_alignParentRight ~~: 与父布局右对齐layout_alignParentBottom : 与父布局下对齐layout_alignParentStart : 为了适配一些从右到左阅读习惯的地区。如适配阿拉伯语,start代表右边,中文是左边。layout_alignParentEnd : 同理取反layout_alignParentStart同理其他marginLeft/marginRight 建议改用 marginStart/ marginEnd
2.3 ScrollView
建议直接使用NestedScrollView ,用法相同,NestedScrollView方便MD风格改动android:layout_width只能是match_parent或具体数值,不能是wrap_content;
2.3 HorizontalScrollView
android:layout_height只能是match_parent或具体数值,不能是wrap_content;
2.4 ConstraintLayout
* 不建议在列表子项使用该布局:ConstraintLayout不适合在列表类的item布局文件中作为根标签使用,列表类滚动时,会出现绘制错误。也不建议在布局中常用,因为各种id强关联,牵一发动全身,遇上朝令夕改的产品经理,会改出血丝眼
更多相关文章
- Android学习笔记―第十一章 Fragment
- Android使用Application总结
- Android(安卓)手势识别向左,右,上,下,滑动的方向
- android 固定横屏幕竖屏
- Android(安卓)popupWindow的使用
- Android(安卓)Jetpack之CameraX使用
- 箭头函数的基础使用
- NPM 和webpack 的基础使用
- Python list sort方法的具体使用