标签:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > </LinearLayout>
注释:android:orientation="vertical"水平线性布局,"horizontal"垂直水平线性
match_parent:
This value declares that the view should expand its width or height to match the width or height of the parent view.
To create a user-editable text field, add an <EditText>
element inside the <LinearLayout>
<EditText android:id="@+id/edit_message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="@string/edit_message" />
res/values/strings.xml
. The result for strings.xml
looks like this:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">My First App</string> <string name="edit_message">Enter a message</string> <string name="button_send">Send</string> <string name="action_settings">Settings</string> <string name="title_activity_main">MainActivity</string> </resources>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_send" />
"wrap_content"
so the button is only as big as necessary to fit the button‘s text.android:id
attribute, because it won‘t be referenced from the activity code.The layout is currently designed so that both the EditText
and Button
widgets are only as big as necessary to fit their content, as shown in figure
Here’s how your complete layout file should now look:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <EditText android:id="@+id/edit_message" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:hint="@string/edit_message" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_send" /> </LinearLayout>
标签:
原文地址:http://www.cnblogs.com/me1105/p/4311714.html