IDEA Android 相对布局(RelativeLayout)示例

柔光的暖阳◎ 2023-10-04 22:36 164阅读 0赞

示例效果如下:

相对布局(RelativeLayout)
BB相对于AA的左边,CC相对于AA的下边,DD相对于BB的下边且相对于CC的右边
EE相对于CC的下边, FF相对于EE的右边且相对于DD的下边

78e8fee92ddd4e9fa132db17fa566997.png

activity_main.xml:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical"
  6. android:background="#ffffff"
  7. >
  8. <!--
  9. 相对布局(RelativeLayout)
  10. BB相对于AA的左边,CC相对于AA的下边,DD相对于BB的下边且相对于CC的右边
  11. EE相对于CC的下边, FF相对于EE的右边且相对于DD的下边
  12. -->
  13. <TextView
  14. android:id="@+id/textAA"
  15. android:layout_width="wrap_content"
  16. android:layout_height="wrap_content"
  17. android:text="AA"
  18. android:textColor="#00FF00"
  19. android:textSize="22sp"
  20. android:layout_marginLeft="20px"/>
  21. <TextView
  22. android:id="@+id/textBB"
  23. android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:layout_toRightOf="@id/textAA"
  26. android:text="BB"
  27. android:textColor="#FF0000"
  28. android:textSize="22sp"
  29. android:layout_marginLeft="20px"/>
  30. <TextView
  31. android:id="@+id/textCC"
  32. android:layout_width="wrap_content"
  33. android:layout_height="wrap_content"
  34. android:layout_below="@id/textAA"
  35. android:text="CC"
  36. android:textColor="#00FFFF"
  37. android:textSize="22sp"
  38. android:layout_marginLeft="20px"/>
  39. <TextView
  40. android:id="@+id/textDD"
  41. android:layout_width="wrap_content"
  42. android:layout_height="wrap_content"
  43. android:layout_below="@id/textBB"
  44. android:layout_toRightOf="@id/textCC"
  45. android:text="DD"
  46. android:textColor="#000000"
  47. android:textSize="22sp"
  48. android:layout_marginLeft="20dip"/>
  49. <EditText
  50. android:id="@+id/editEE"
  51. android:layout_width="wrap_content"
  52. android:layout_height="wrap_content"
  53. android:hint="EE"
  54. android:inputType="textPersonName"
  55. android:layout_below="@id/textCC"
  56. android:layout_marginLeft="20px"
  57. android:layout_marginTop="20dp"
  58. android:ems="10"
  59. />
  60. <Button
  61. android:id="@+id/btnFF"
  62. android:layout_width="wrap_content"
  63. android:layout_height="wrap_content"
  64. android:text="FF"
  65. android:layout_toRightOf="@id/editEE"
  66. android:layout_below="@id/textDD"
  67. android:layout_marginLeft="20px"
  68. android:layout_marginTop="20dp"
  69. />
  70. </RelativeLayout>

附:相对布局参数说明:

4fda68f2dd5946c598b4521e1eabfa17.png

发表评论

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

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

相关阅读