Android编程之绝对布局AbsoluteLayout和相对布局RelativeLayout实例详解

2019-12-10 19:40:45于丽
易采站长站为您分析Android编程之绝对布局AbsoluteLayout和相对布局RelativeLayout实现方法,结合实例形式详细分析了Android绝对布局AbsoluteLayout和相对布局RelativeLayout的原理与使用技巧,需要的朋友可以参考下  

本文实例分析了Android编程之绝对布局AbsoluteLayout和相对布局RelativeLayout。,具体如下:

 一、绝对布局AbsoluteLayout

绝对定位AbsoluteLayout,又可以叫做坐标布局,可以直接指定子元素的绝对位置,这种布局简单直接,直观性强,但是由于手机屏幕尺寸差别比较大,使用绝对定位的适应性会比较差。

下面我们举一个例子看看:例子里的机器人图片大小是250X250,可以看到我们使用android:layout_x和android:layout_y来指定子元素的纵横坐标。

XML/HTML代码:

<?xml version="1.0" encoding="utf-8"?> 
<AbsoluteLayout android:id="@+id/AbsoluteLayout01" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://www.easck.com/apk/res/android" 
android:background="#fff"><ImageView 
android:src="@drawable/android" 
android:layout_y="40dip" 
android:layout_width="wrap_content" 
android:layout_x="35dip" 
android:id="@+id/ImageView01" 
android:layout_height="wrap_content"> 
</ImageView> 
<TextView 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:id="@+id/TextView01" 
android:text="Android2.2 学习指南" 
android:textColor="#0f0" 
android:textSize="28dip" 
android:layout_y="330dip" 
android:layout_x="35dip“> 
</TextView> 
<TextView 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:id="@+id/TextView02" 
android:text="图文并茂,理论清晰,操作性强" 
android:textColor="#333" 
android:textSize="18dip" 
android:layout_y="365dip" 
android:layout_x="35dip“> 
</TextView> 
</AbsoluteLayout>

让我们看一下在WQVGA的模拟器下的显示效果:

Android编程之绝对布局AbsoluteLayout和相对布局RelativeLayout实例详解