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?
- <? XML version= "1.0" encoding="Utf-8"?>
- <!--
- <linearlayout>
- Linear layout configuration, in which all components are lined up from top to bottom
- -->
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <!-- android:orientation="vertical" indicates vertical alignment
- android:orientation="Horizontal" indicates horizontal alignment
- android:layout_width="Fill_parent" defines the width that the current view can consume on the screen, and fill_parent fills the entire screen.
- 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
- Layout_weight is used to assign values to the importance of many views in a linear layout.
- All views have a layout_weight value, which defaults to zero, meaning it needs to be displayed
- How large a view occupies is the screen space. If you assign a value higher than zero, the parent view
- The available space in the graph is split, and the split size depends on the layout_weight of each view
- Value and the overall layout_weight value of the value in the current screen layout and the other view screen cloth
- Percentage of the Layout_weight value of the bureau.
- For example, let's say we have a text label and two text editing elements in the horizontal direction.
- The text label does not specify a layout_weight value, so it will occupy the minimum space needed to provide it.
- If the layout_weight value of each of the two text-editing elements is set to 1, the two are split equally
- The remaining width in the parent view layout (because we declare the importance of the two equal). If two X
- The text editing element where the first Layout_weight value is set to 1, and the second is set to 2,
- The remaining space of two-thirds points to the first, One-third points to the second (the smaller the value, the more important
- The higher the degree).
- -->
- <linearlayout
- android:orientation="Horizontal"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_weight="1">
- <TextView
- android:text="Red"
- android:gravity="Center_horizontal"
- android:background="#aa0000"
- android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:layout_weight="1"/>
- <TextView
- android:text="Green"
- android:gravity="Center_horizontal"
- android:background="#00aa00"
- android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:layout_weight="1"/>
- <TextView
- android:text="Blue"
- android:gravity="Center_horizontal"
- android:background="#0000aa"
- android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:layout_weight="1"/>
- <TextView
- android:text="Yellow"
- android:gravity="Center_horizontal"
- android:background="#aaaa00"
- android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:layout_weight="1"/>
- </linearlayout>
- <linearlayout
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_weight="2">
- <TextView
- android:text="Row One"
- android:textsize="15pt"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"/>
- <TextView
- android:text="Row "
- android:textsize="15pt"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"/>
- <TextView
- android:text="row three"
- android:textsize="15pt"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"/>
- <TextView
- android:text="Row four"
- android:textsize="15pt"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"/>
- </linearlayout>
- </LinearLayout>
Go Android:layout_width and Android:width in Android