Android突击:实现屏幕四角和居中摆放控件的布局

本文介绍了一种使用LinearLayout实现屏幕三等分布局的方法。通过设置不同的权重(weight),可以灵活地调整各部分的比例,达到理想的布局效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

要实现这样的布局,其实就是将屏幕纵向三等分,上下的进行平分就好啦。用:Iienarlayout实现。
代码:

   
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical" android:layout_width="fill_parent"
  4. android:layout_height="fill_parent">
  5. <!-- 上部 -->
  6. <LinearLayout android:orientation="horizontal"
  7. android:layout_width="fill_parent" android:layout_height="fill_parent"
  8. android:layout_weight="1">
  9. <LinearLayout android:orientation="vertical"
  10. android:layout_width="fill_parent" android:layout_height="fill_parent"
  11. android:layout_weight="1">
  12. <Button android:layout_width="wrap_content"
  13. android:layout_height="wrap_content" android:text="左上按钮"
  14. android:layout_gravity="left" />
  15. </LinearLayout>
  16. <LinearLayout android:orientation="vertical"
  17. android:layout_width="fill_parent" android:layout_height="fill_parent"
  18. android:layout_weight="1">
  19. <Button android:layout_width="wrap_content"
  20. android:layout_height="wrap_content" android:text="右上按钮"
  21. android:layout_gravity="right" />
  22. </LinearLayout>
  23. </LinearLayout>
  24. <!-- 中部 -->
  25. <LinearLayout android:orientation="vertical"
  26. android:layout_width="fill_parent" android:layout_height="fill_parent"
  27. android:layout_weight="1" android:gravity="center">
  28. <Button android:layout_width="wrap_content"
  29. android:layout_height="wrap_content" android:text="中心按钮" />
  30. </LinearLayout>
  31. <!-- 底部 -->
  32. <LinearLayout android:orientation="horizontal"
  33. android:layout_width="fill_parent" android:layout_height="fill_parent"
  34. android:layout_weight="1">
  35. <LinearLayout android:orientation="vertical"
  36. android:layout_width="fill_parent" android:layout_height="fill_parent"
  37. android:layout_weight="1" android:gravity="left|bottom">
  38. <Button android:layout_width="wrap_content"
  39. android:layout_height="wrap_content" android:text="左下按钮" />
  40. </LinearLayout>
  41. <LinearLayout android:orientation="vertical"
  42. android:layout_width="fill_parent" android:layout_height="fill_parent"
  43. android:layout_weight="1" android:gravity="right|bottom">
  44. <Button android:layout_width="wrap_content"
  45. android:layout_height="wrap_content" android:text="右下按钮"
  46. />
  47. </LinearLayout>
  48. </LinearLayout>
  49. </LinearLayout>
weight属性比较重要的,若weight值都相等,相当于等分,weight值越大,占的比重越小。






















转载于:https://www.cnblogs.com/zhuzhenfeng/p/4637777.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值