05 五大布局&布局优化
*LinearLayout --线性布局
属性
android:orientation= --布局方式 vertical/hhorizontal
android:layout_weight --占比重
android:baselineAligned --基准线对齐
*RelativeLayout --相对布局
属性
移动能力
android:layout_toLeftOf --到左边
android:layout_toRightOf --到右边
android:layout_centerInParent --放置到父控件水平居中,垂直居中
android:layout_centerVertical --放置到父控件垂直居中
android:layout_centerHorizontal --放置到父控件水平居中
一对使用时具有拉伸控件的能力
android:layout_below --控件下方
android:layout_above --控件上方
android:layout_align[Parent]Top --对齐到指定ID控件的top
android:layout_align[Parent]Bottom --对齐到指定ID控件的Bottom
android:layout_align[Parent]Left --对齐到指定ID控件的Left
android:layout_align[Parent]Right --对齐到指定ID控件的Right
android:layout_align[Parent]BaseLine --对齐到指定ID控件的基准线
android:layout_alignStart --对齐到指定ID开始位置
android:layout_alignStop --对齐到指定ID结束位置
android:layout_alignParentStart --对齐到父控件开始位置
android:layout_alignParentStop --对齐到父控件结束位置
通过相对布局实现水平对半布局.
<View
android:id="@+id/center_View"
android:layout_centerHorizontal="true"
android:layout_width="0dp"
android:layout_height="0dp"></View>
<ImageView
android:id="@+id/left_Image"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/center_View"
android:layout_width="0dp"
android:layout_height="200dp"
android:background="@color/White"
/>
<ImageView
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/left_Image"
android:layout_width="0dp"
android:layout_height="200dp"
android:background="@color/Black"
/>
*FrameLayout --跌加布局
属性
AbsoluteLayout --绝对布局
TableLayout --表格布局
属性
android:stretchColumns="0,1,2"//设置列0、1、2为可伸展列。
android:stretchColumns="0,1,2"//设置列0、1、2为可伸展列。
<TableRow> --表示一行
</TableRow>
布局是如何绘制的?
布局的绘制根据从上到下,像树一样检索.
可能产生哪些性能问题?
如果层次过多会影响到解析布局性能.
如何优化?
官方建议嵌套少于10层.
如何减少:通过相对布局.
搭积木方式,通过组合生成一个新的控件.
布局的一些其他属性
<include layout="@"/> --引入布局,重复利用布局.
<merge/> :减少视图层次
<ViewStub/> :需要时加载
本人重点推荐新的布局方式
ConstraintLayout点击立即转跳