Because the
LinearLayout
is the root view in the layout, it should fill the entire screen area that's available to the app by setting the width and height to"
match_parent
"
. This value declares that the view should expand its width or height to match the width or height of the parent view.<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_width="wrap_content" android:layout_height="wrap_content" android:hint="@string/edit_message" /> </LinearLayout>
android:hint
"@string/edit_message
"
value refers to a string resource defined in a separate file. Because this refers to a concrete resource (not just an identifier), it does not need the plus sign. However, because you haven't defined the string resource yet, you’ll see a compiler error at first. You'll fix this in the next section by defining the string.Add String Resources
By default, your Android project includes a string resource file at
res/values/strings.xml
. Here, you'll add two new strings.- From the
res/values/
directory, openstrings.xml
. - Add two strings so that your file 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> </resources>
沒有留言:
張貼留言