本章节翻译自《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. <?xmlversion="1.0"encoding="utf-8"?>
  2. <AbsoluteLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent">
  5. <Button
  6. android:layout_width="188dp"
  7. android:layout_height="wrap_content"
  8. android:layout_x="126px"
  9. android:layout_y="361px"
  10. android:text="Button"/>
  11. <Button
  12. android:layout_width="113dp"
  13. android:layout_height="wrap_content"
  14. android:layout_x="12px"
  15. android:layout_y="361px"
  16. android:text="Button"/>
  17. </AbsoluteLayout>
下面是效果图,使用了android:layout_x和android_y属性,把两个Button放置在了确切的位置上。


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

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

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

更多相关文章

  1. android文件、资源读取总结
  2. Android(安卓)Listview切换动画,扩展到任意view切换之间动画实现
  3. Android几行代码解决键盘遮挡问题
  4. Android实现沉浸式状态栏
  5. android通过自定义toast实现悬浮通知效果的示例代码
  6. Fragment 在Android(安卓)SDK1.6上实现
  7. android studio开发教程 ListActivity的2种使用方法:系统默认布局
  8. Android(安卓)gradle和gradle插件配置
  9. Android(安卓)fill_parent和wrap_content分析

随机推荐

  1. Android中的下拉列表-自定义选项界面样式
  2. ConstraintLayout子View设置match_parent
  3. Android(安卓)UI
  4. 如何卸载Eclipse中ArcGIS for Android的
  5. node.js+android http请求响应
  6. Android(安卓)获取sdcard音乐文件
  7. Android(安卓)XmlSerializer 换行
  8. Ubuntu 10.4下 Android(安卓)ADT的编译
  9. Android(安卓)Suspend
  10. Mms模块ConversationList流程分析