Android 绝对布局
线性布局有两种方式指定空间位置 一是水平的而是竖向的
Layout线性布局部分代码
<androidx.constraintlayout.widget.ConstraintLayout 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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two!"
android:bacakgroudt="#FFFFFFFF!"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one!"
android:bacakgroudt="#FF000000!"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
其次可以嵌套另一个类
相对布局(RelativeLayout)
也有两种形式,一种是相对于容器而言,一种是相对于控件而言
相对布局 如果添加一个组件,默认最上角对齐
部分代码显示相对布局
<androidx.constraintlayout.widget.ConstraintLayout
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”>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="41dp"
tools:layout_editor_absoluteY="29dp" />
<ImageView
android:id="@+id/imageView"
android:layout_width="368dp"
android:layout_height="358dp"
tools:layout_editor_absoluteX="21dp"
tools:layout_editor_absoluteY="186dp"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="291dp"
tools:layout_editor_absoluteY="29dp" />
</androidx.constraintlayout.widget.ConstraintLayout>