Android基础#13: Layout经典布局--绝对布局AbsoluteLayout的使用

朴灿烈づ我的快乐病毒、 2023-10-16 21:56 67阅读 0赞

世间无绝对,真是这样的么?——-箴言——-

内容简介:
Android提供了AbsoluteLayout,即绝对布局, 即设置控件的绝对位置,控件坐标”从x,y”开始进行排列。
在使用AbsoluteLayout布局方式时,需要指定空间的x,y精确坐标。

举例如下:
下面是一个简单的父布局为AbsoluteLayout的xml文件:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:background="#CCCCCC"
  6. >
  7. <Button
  8. android:background="#11EE11"
  9. android:layout_x="48px"
  10. android:layout_y="48px"
  11. android:layout_width="wrap_content"
  12. android:layout_height="wrap_content"
  13. android:text="按钮1"></Button>
  14. <Button
  15. android:background="#1111DD"
  16. android:layout_x="300px"
  17. android:layout_y="100px"
  18. android:layout_width="wrap_content"
  19. android:layout_height="wrap_content"
  20. android:text="按钮2"></Button>
  21. <Button
  22. android:background="#CC2222"
  23. android:layout_x="200px"
  24. android:layout_y="300px"
  25. android:layout_width="wrap_content"
  26. android:layout_height="wrap_content"
  27. android:text="按钮3"></Button>
  28. </AbsoluteLayout>

效果如下:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xpcmFua2U_size_16_color_FFFFFF_t_70

可见,在AbsoluteLayout中,按钮被固定在绝对坐标的位置上。

注:事实上,不推荐使用该布局。因为在实际应用中,LinearLayout,FrameLayout,FragmeLayout几乎可以完全满足UI的各种布局需求。

发表评论

表情:
评论列表 (有 0 条评论,67人围观)

还没有评论,来说两句吧...

相关阅读