Go Android:layout_width and Android:width in Android

Source: Internet
Author: User

Android:width is actually the width of the text (TextView) above the definition of the control, which, of course, also works with Android:layout_width, if Android:layout_width= "Fill_ Parent "words, then setting android:width is meaningless


Android:layout_width actually can achieve android:width effect, I think this should be why in the Android instance does not see the reason that someone uses android:width.


If you want to talk about the difference between the two, it is:
The value of android:width is usually "100DP";
The value of the android:layout_width is generally "fill_parent", "Wrap_content", "match_parent". Of course, it can also be like the former, set the value of the.


The property with "layout" refers to the entire control, which is the relationship between the parent control, such as the alignment of Layout_gravity in the parent control, Layout_margin is the gap between controls of the same level, and so on;

A property without "layout" is the format of the text in the accusation, such as gravity, which refers to the alignment of the text, and so on, where the format of the text is constrained by the properties of its control in the parent control.


An example of borrowing a Daniel: http://zhangcong170.iteye.com/blog/423173

[HTML]View Plaincopyprint?
    1. <? XML version= "1.0" encoding="Utf-8"?>
    2. <!--
    3. <linearlayout>
    4. Linear layout configuration, in which all components are lined up from top to bottom
    5. -->
    6. <LinearLayout
    7. xmlns:android="http://schemas.android.com/apk/res/android"
    8. android:orientation="vertical"
    9. android:layout_width="fill_parent"
    10. android:layout_height="fill_parent">
    11. <!-- android:orientation="vertical" indicates vertical alignment
    12. android:orientation="Horizontal" indicates horizontal alignment
    13. android:layout_width="Fill_parent" defines the width that the current view can consume on the screen, and fill_parent fills the entire screen.
    14. android:layout_height="wrap_content": Changes the width or height of the view as the text field is different. A bit of automatic setting of the box or height meaning
    15. Layout_weight is used to assign values to the importance of many views in a linear layout.
    16. All views have a layout_weight value, which defaults to zero, meaning it needs to be displayed
    17. How large a view occupies is the screen space. If you assign a value higher than zero, the parent view
    18. The available space in the graph is split, and the split size depends on the layout_weight of each view
    19. Value and the overall layout_weight value of the value in the current screen layout and the other view screen cloth
    20. Percentage of the Layout_weight value of the bureau.
    21. For example, let's say we have a text label and two text editing elements in the horizontal direction.
    22. The text label does not specify a layout_weight value, so it will occupy the minimum space needed to provide it.
    23. If the layout_weight value of each of the two text-editing elements is set to 1, the two are split equally
    24. The remaining width in the parent view layout (because we declare the importance of the two equal). If two X
    25. The text editing element where the first Layout_weight value is set to 1, and the second is set to 2,
    26. The remaining space of two-thirds points to the first, One-third points to the second (the smaller the value, the more important
    27. The higher the degree).
    28. -->
    29. <linearlayout
    30. android:orientation="Horizontal"
    31. android:layout_width="fill_parent"
    32. android:layout_height="fill_parent"
    33. android:layout_weight="1">
    34. <TextView
    35. android:text="Red"
    36. android:gravity="Center_horizontal"
    37. android:background="#aa0000"
    38. android:layout_width="wrap_content"
    39. android:layout_height="fill_parent"
    40. android:layout_weight="1"/>
    41. <TextView
    42. android:text="Green"
    43. android:gravity="Center_horizontal"
    44. android:background="#00aa00"
    45. android:layout_width="wrap_content"
    46. android:layout_height="fill_parent"
    47. android:layout_weight="1"/>
    48. <TextView
    49. android:text="Blue"
    50. android:gravity="Center_horizontal"
    51. android:background="#0000aa"
    52. android:layout_width="wrap_content"
    53. android:layout_height="fill_parent"
    54. android:layout_weight="1"/>
    55. <TextView
    56. android:text="Yellow"
    57. android:gravity="Center_horizontal"
    58. android:background="#aaaa00"
    59. android:layout_width="wrap_content"
    60. android:layout_height="fill_parent"
    61. android:layout_weight="1"/>
    62. </linearlayout>
    63. <linearlayout
    64. android:orientation="vertical"
    65. android:layout_width="fill_parent"
    66. android:layout_height="fill_parent"
    67. android:layout_weight="2">
    68. <TextView
    69. android:text="Row One"
    70. android:textsize="15pt"
    71. android:layout_width="fill_parent"
    72. android:layout_height="wrap_content"
    73. android:layout_weight="1"/>
    74. <TextView
    75. android:text="Row "
    76. android:textsize="15pt"
    77. android:layout_width="fill_parent"
    78. android:layout_height="wrap_content"
    79. android:layout_weight="1"/>
    80. <TextView
    81. android:text="row three"
    82. android:textsize="15pt"
    83. android:layout_width="fill_parent"
    84. android:layout_height="wrap_content"
    85. android:layout_weight="1"/>
    86. <TextView
    87. android:text="Row four"
    88. android:textsize="15pt"
    89. android:layout_width="fill_parent"
    90. android:layout_height="wrap_content"
    91. android:layout_weight="1"/>
    92. </linearlayout>
    93. </LinearLayout>

Go Android:layout_width and Android:width in Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.