绝对布局中将所有的子元素通过设置android:layout_x 和 android:layout_y属性,将子元素的坐标位置固定下来,即坐标(android:layout_x, android:layout_y) ,layout_x用来表示横坐标,layout_y用来表示纵坐标。 屏幕左上角为坐标(0,0),横向往右为正方,纵向往下为正方。实际应用中,这种布局用的比较少,因为Android终端一般机型比较多,各自的屏幕大小。分辨率等可能都不一样,如果用绝对布局,可能导致在有的终端上显示不全等.
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.xspacing.absolutelayout.MainActivity" >
<TextView
android:layout_x="100dp"
android:layout_y="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AbsoluteLayout" />
</AbsoluteLayout>
本文介绍了Android开发中的绝对布局,通过设置子元素的android:layout_x和android:layout_y属性来确定其坐标位置。虽然简单直观,但因不同设备屏幕尺寸及分辨率差异较大,在实际开发中较少使用。
9万+

被折叠的 条评论
为什么被折叠?



