• app简单控件了解——常用布局——相对布局RelativeLayout


    相对位置的属性取值

    相对位置说明

    layout_toLeftOf

    当前视图在指定视图的左边

    layout_toRightOf

    当前视图在指定视图的右边

    layout_above

    当前视图在指定视图的上方

    layout_below

    当前视图在指定视图的下方

    layout_alignLeft

    当前视图与指定视图的左侧对齐

    layout_alignRight

    当前视图与指定视图的右侧对齐

    layout_alignTop

    当前视图与指定视图的顶部对齐

    layout_alignBottom

    当前视图与指定视图的底部对齐

    layout_centerInParent

    当前视图在上级视图中间

    layout_centerHorizontal

    当前视图在上级视图的水平方向居中

    layout_centerVertical

    当前视图在上级视图的垂直方向居中

    layout_alignParentLeft

    当前视图与上级视图的左侧对齐

    layout_alignParentRight

    当前视图与上级视图的右侧对齐

    layout_alignParentTop

    当前视图与上级视图的顶部对齐

    layout_alignParentBottom

    当前视图与上级视图的底部对齐

    书本示例:

    1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    2. android:layout_width="match_parent"
    3. android:layout_height="150dp" >
    4. <TextView
    5. android:id="@+id/tv_center"
    6. android:layout_width="wrap_content"
    7. android:layout_height="wrap_content"
    8. android:layout_centerInParent="true"
    9. android:background="#ffffff"
    10. android:text="我在中间"
    11. android:textSize="11sp"
    12. android:textColor="#000000" />
    13. <TextView
    14. android:id="@+id/tv_center_horizontal"
    15. android:layout_width="wrap_content"
    16. android:layout_height="wrap_content"
    17. android:layout_centerHorizontal="true"
    18. android:background="#eeeeee"
    19. android:text="我在水平中间"
    20. android:textSize="11sp"
    21. android:textColor="#000000" />
    22. <TextView
    23. android:id="@+id/tv_center_vertical"
    24. android:layout_width="wrap_content"
    25. android:layout_height="wrap_content"
    26. android:layout_centerVertical="true"
    27. android:background="#eeeeee"
    28. android:text="我在垂直中间"
    29. android:textSize="11sp"
    30. android:textColor="#000000" />
    31. <TextView
    32. android:id="@+id/tv_parent_left"
    33. android:layout_width="wrap_content"
    34. android:layout_height="wrap_content"
    35. android:layout_alignParentLeft="true"
    36. android:background="#eeeeee"
    37. android:text="我跟上级左边对齐"
    38. android:textSize="11sp"
    39. android:textColor="#000000" />
    40. <TextView
    41. android:id="@+id/tv_parent_right"
    42. android:layout_width="wrap_content"
    43. android:layout_height="wrap_content"
    44. android:layout_alignParentRight="true"
    45. android:background="#eeeeee"
    46. android:text="我跟上级右边对齐"
    47. android:textSize="11sp"
    48. android:textColor="#000000" />
    49. <TextView
    50. android:id="@+id/tv_parent_top"
    51. android:layout_width="wrap_content"
    52. android:layout_height="wrap_content"
    53. android:layout_alignParentTop="true"
    54. android:background="#eeeeee"
    55. android:text="我跟上级顶部对齐"
    56. android:textSize="11sp"
    57. android:textColor="#000000" />
    58. <TextView
    59. android:id="@+id/tv_parent_bottom"
    60. android:layout_width="wrap_content"
    61. android:layout_height="wrap_content"
    62. android:layout_alignParentBottom="true"
    63. android:background="#eeeeee"
    64. android:text="我跟上级底部对齐"
    65. android:textSize="11sp"
    66. android:textColor="#000000" />
    67. <TextView
    68. android:id="@+id/tv_left_center"
    69. android:layout_width="wrap_content"
    70. android:layout_height="wrap_content"
    71. android:layout_toLeftOf="@+id/tv_center"
    72. android:layout_alignTop="@+id/tv_center"
    73. android:background="#eeeeee"
    74. android:text="我在中间左边"
    75. android:textSize="11sp"
    76. android:textColor="#000000" />
    77. <TextView
    78. android:id="@+id/tv_right_center"
    79. android:layout_width="wrap_content"
    80. android:layout_height="wrap_content"
    81. android:layout_toRightOf="@+id/tv_center"
    82. android:layout_alignBottom="@+id/tv_center"
    83. android:background="#eeeeee"
    84. android:text="我在中间右边"
    85. android:textSize="11sp"
    86. android:textColor="#000000" />
    87. <TextView
    88. android:id="@+id/tv_above_center"
    89. android:layout_width="wrap_content"
    90. android:layout_height="wrap_content"
    91. android:layout_above="@+id/tv_center"
    92. android:layout_alignLeft="@+id/tv_center"
    93. android:background="#eeeeee"
    94. android:text="我在中间上面"
    95. android:textSize="11sp"
    96. android:textColor="#000000" />
    97. <TextView
    98. android:id="@+id/tv_below_center"
    99. android:layout_width="wrap_content"
    100. android:layout_height="wrap_content"
    101. android:layout_below="@+id/tv_center"
    102. android:layout_alignRight="@+id/tv_center"
    103. android:background="#eeeeee"
    104. android:text="我在中间下面"
    105. android:textSize="11sp"
    106. android:textColor="#000000" />
    107. </RelativeLayout>

    改变了背景颜色的示例:

    1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    2. android:layout_width="match_parent"
    3. android:background="@color/purple_700"
    4. android:layout_height="150dp" >
    5. <TextView
    6. android:id="@+id/tv_center"
    7. android:layout_width="wrap_content"
    8. android:layout_height="wrap_content"
    9. android:layout_centerInParent="true"
    10. android:background="#F4511E"
    11. android:text="我在中间"
    12. android:textSize="11sp"
    13. android:textColor="#000000" />
    14. <TextView
    15. android:id="@+id/tv_center_horizontal"
    16. android:layout_width="wrap_content"
    17. android:layout_height="wrap_content"
    18. android:layout_centerHorizontal="true"
    19. android:background="#F4511E"
    20. android:text="我在水平中间"
    21. android:textSize="11sp"
    22. android:textColor="#000000" />
    23. <TextView
    24. android:id="@+id/tv_center_vertical"
    25. android:layout_width="wrap_content"
    26. android:layout_height="wrap_content"
    27. android:layout_centerVertical="true"
    28. android:background="#F4511E"
    29. android:text="我在垂直中间"
    30. android:textSize="11sp"
    31. android:textColor="#000000" />
    32. <TextView
    33. android:id="@+id/tv_parent_left"
    34. android:layout_width="wrap_content"
    35. android:layout_height="wrap_content"
    36. android:layout_alignParentLeft="true"
    37. android:background="#F4511E"
    38. android:text="我跟上级左边对齐"
    39. android:textSize="11sp"
    40. android:textColor="#000000" />
    41. <TextView
    42. android:id="@+id/tv_parent_right"
    43. android:layout_width="wrap_content"
    44. android:layout_height="wrap_content"
    45. android:layout_alignParentRight="true"
    46. android:background="#F4511E"
    47. android:text="我跟上级右边对齐"
    48. android:textSize="11sp"
    49. android:textColor="#000000" />
    50. <TextView
    51. android:id="@+id/tv_parent_top"
    52. android:layout_width="wrap_content"
    53. android:layout_height="wrap_content"
    54. android:layout_alignParentTop="true"
    55. android:background="#F4511E"
    56. android:text="我跟上级顶部对齐"
    57. android:textSize="11sp"
    58. android:textColor="#000000" />
    59. <TextView
    60. android:id="@+id/tv_parent_bottom"
    61. android:layout_width="wrap_content"
    62. android:layout_height="wrap_content"
    63. android:layout_alignParentBottom="true"
    64. android:background="#F4511E"
    65. android:text="我跟上级底部对齐"
    66. android:textSize="11sp"
    67. android:textColor="#000000" />
    68. <TextView
    69. android:id="@+id/tv_left_center"
    70. android:layout_width="wrap_content"
    71. android:layout_height="wrap_content"
    72. android:layout_alignTop="@+id/tv_center"
    73. android:layout_toLeftOf="@+id/tv_center"
    74. android:background="#F4511E"
    75. android:text="我在中间左边"
    76. android:textColor="#000000"
    77. android:textSize="11sp" />
    78. <TextView
    79. android:id="@+id/tv_right_center"
    80. android:layout_width="wrap_content"
    81. android:layout_height="wrap_content"
    82. android:layout_toRightOf="@+id/tv_center"
    83. android:layout_alignBottom="@+id/tv_center"
    84. android:background="#F4511E"
    85. android:text="我在中间右边"
    86. android:textSize="11sp"
    87. android:textColor="#000000" />
    88. <TextView
    89. android:id="@+id/tv_above_center"
    90. android:layout_width="wrap_content"
    91. android:layout_height="wrap_content"
    92. android:layout_above="@+id/tv_center"
    93. android:layout_alignLeft="@+id/tv_center"
    94. android:background="#F4511E"
    95. android:text="我在中间上面"
    96. android:textSize="11sp"
    97. android:textColor="#000000" />
    98. <TextView
    99. android:id="@+id/tv_below_center"
    100. android:layout_width="wrap_content"
    101. android:layout_height="wrap_content"
    102. android:layout_below="@+id/tv_center"
    103. android:layout_alignRight="@+id/tv_center"
    104. android:background="#F4511E"
    105. android:text="我在中间下面"
    106. android:textSize="11sp"
    107. android:textColor="#000000" />
    108. </RelativeLayout>

  • 相关阅读:
    网课查题公众号题库搭建过程
    【计算机网络笔记】DHCP协议
    VS系列多通道振弦温度采发仪的选型与开机操作
    外观设计的基本功能与产品特点
    从数学到算法
    R语言ggplot2可视化:ggcharts包的bar_chart函数可视化条形图、bar_chart函数自动排序条形图并水平显示
    机器学习分类模型评价指标之混淆矩阵
    Linux网络服务之SSH(远程访问及控制)
    数学建模——差分方程结论介绍
    《canvas》之第19章 canvas游戏开发
  • 原文地址:https://blog.csdn.net/m0_61442607/article/details/125494954