由开发人员控制,通过坐标来定位。每个子组件都可以通过layout_x
和layout_y
来指定X,Y坐标。
登录界面:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout 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_x="20dp"
android:layout_y="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户名:"
android:textColor="#000"
android:hint="请输入用户名"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:layout_x="80dp"
android:layout_y="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="200px" />
<TextView
android:layout_x="20dp"
android:layout_y="80dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:text="密 码"/>
<EditText
android:layout_x="80dp"
android:layout_y="75dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="200px"
android:password="true"/>
<Button
android:layout_x="130dp"
android:layout_y="135dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="登 录"/>
</AbsoluteLayout>
- px:像素,每个px代表屏幕上的一个点
- dip或dp:设备独立像素,一种基于屏幕密度的抽象单位,在每英寸160点的显示器上,1dp=1px。但随着屏幕密度的改变,dp与px的换算会发生改变。
- sp:比例像素,主要处理字体的大小,可以根据用户的字体大小首选项进行缩放。
- in:英寸,标准长度单位
- mm:毫米,标准长度单位
- pt:磅,标准长度单位,1/72英寸