布局管理器是什么
布局管理器类似于棋盘,其中的棋子就是组件。
常用的布局管理器
RelativeLayout(相对布局管理器)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"//用来定义工具命名空间的
android:layout_width="match_parent"//设置布局宽度——与父容器相同
android:layout_height="match_parent"//设置布局高度
tools:context=".MainActivity">//用于指向使用这个布局的Activity的,不会被打包进布局文件的
</RelativeLayout>
还有两个属性分别是:
android:gravity 用于设置布局管理器中各子组件的摆放方式的
android:ignoreGravity 用于设置那个子组件可以不受上面的属性的影响的(需要在组件中添加id)
还提供了一个内部类:
LayoutParams:提供了属性:
android:layout_above / android:layout_below / android:layout_toLeftOf / android:layout_toRightOf:用于指定组件相对于另一个组件参考位置的
android:layout_alignParentBottom / android:layout_alignParentLeft / android:layout_alignParentRight / android:layout_alignParentTop:用于设置组件与布局管理器是那边对其的,都是Boolean类型的,当值为True时表示与那一边对齐。
android:layout_alignBottom / android:layout_alignL