【Android 开发教程】AbsoluteLayout绝对布局

本章节翻译自《Beginning-Android-4-Application-Development》,如有翻译不当的地方,敬请指出。

原书购买地址http://www.amazon.com/Beginning-Android-4-Application-Development/dp/1118199545/


使用AbsoluteLayout,可以指定它其中的子View的确切位置。观察如下main.xml中的代码:

[html] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent" >  
  5.   
  6.     <Button  
  7.         android:layout_width="188dp"  
  8.         android:layout_height="wrap_content"  
  9.         android:layout_x="126px"  
  10.         android:layout_y="361px"  
  11.         android:text="Button" />  
  12.   
  13.     <Button  
  14.         android:layout_width="113dp"  
  15.         android:layout_height="wrap_content"  
  16.         android:layout_x="12px"  
  17.         android:layout_y="361px"  
  18.         android:text="Button" />  
  19.   
  20. </AbsoluteLayout>  
下面是效果图,使用了android:layout_x和android_y属性,把两个Button放置在了确切的位置上。


但当activity被绘制在一个高分辨率的屏幕上时,AbsoluteLayout就会出现某些问题。

下图是,在使用同样代码的前提下,高分辨率屏幕上显示出来的效果。

出于这个原因,从Android1.5开始,Google官方已经不推荐使用这个布局了,尽管它现在还是可以使用的。在创建UI的时候,应该避免使用AbsoluteLayout这个布局,因为,Android并不确保会在将来的版本中还继续支持它。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值