絕對(duì)布局的概念
絕對(duì)布局(AbsoluteLayout)是通過(guò)指定x、y坐標(biāo)來(lái)控制每一個(gè)控件位置的。
常用屬性
| 屬性 | 含義 |
|---|---|
| android:layout_x | x坐標(biāo) |
| android:layout_y | y坐標(biāo) |
例如:設(shè)置按鈕處于x 50,y 50的位置
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="50dp"
android:layout_y="50dp"/>
</AbsoluteLayout>
常用度量單位
px:像素,即在屏幕中可以顯示最小元素單位。
pt:磅數(shù),一磅等于1/72英寸,一般pt會(huì)作為字體的單位來(lái)顯示。
dp:基于屏幕密度的抽象單位。不同設(shè)備有不同的顯示效果,根據(jù)設(shè)備分辨率的不同來(lái)確定控件的尺寸。
sp:可伸縮像素,采用與dp相同的設(shè)計(jì)理念,推薦設(shè)置文字大小時(shí)使用。