Preface
The user interface of the Android app is built on top of the two objects, view and ViewGroup. View is a generic UI component. Like button, input box and so on.
ViewGroup is a container for invisible view that defines how the sub-view is laid out. Similar in a grid or a vertical list.
Android provides a set of XML tag words to define the page display of the UI.
define a linear layout
1. Under the Res/layout folder. Open Activity_my.xml (my is the name of the activity you defined)
You create a blankactivity template file that includes the project master, including a relativelayout root view and a TextView child view.
2. Delete <TextView> elements
3. Change the <RelativeLayout> into <LinearLayout> .
4. Join android:orientation attribute and set the value to &NBSP; " horizontal "
5. Removing the properties of android:padding and tools:context
The changed files are similar:
<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>
LinearLayout is a view group (a subclass of ViewGroup) that is set up with the layoutandroid:orientationThe handle view is arranged in a horizontal or vertical direction.
android:layout_widthAndandroid:layout_height 这两个属性用来设置布局的大小。这个值设置成 "match_parent" 就会撑开他的长宽和父View 适应。
Too much about the layout of the content, can participate in the Examiner's introduction:
Http://developer.android.com/guide/topics/ui/declaring-layout.html
Add a text input box
1. In ACTIVITY_MY.XML&NBSP; , <LINEARLAYOUT> &NBSP; , define the <EditText> element, the value of the attribute" id "is set to @+id/edit_message
2. layout_width and layout_height is set to" wrap_content "
3. Define the properties of the hint, with a value of edit_message .
Res/layout/activity_my.xml, the complete definition is similar:
<edittext android:id= "@+id/edit_message" android:layout_width= "wrap_content" android:layout_height= " Wrap_content " android:hint=" @string/edit_message "/>
attribute and attribute value description
android:id --
@+id/edit_message
@ means: But when a resource object needs to be read from XML
+: But when you first define a resource ID, you need to add a "+" number. When compiling the app, the SDK tool will create a new resource ID in Gen\r.java with the name
ID: is type (processing ID type, and string type)
Edit_message: This will show you how to create the
android:layout_widthAndandroid:layout_height
"Wrap_content"
Overrides set the actual width and height. Wrap_content This value allows the view to fill the entire content.
android:hint
When the input box is empty. Sets the default display string.
Adding a string resource
Default state. Android Project will import string resource filesres/values/strings.xml. Here, add the following"edit_message"wait1. OpenRes/values/strings.xml2. Join a row"Edit_message", the value is set to "Enter a message". 3. Add another line,The "Button_send" value is set to "send". Res/values/strings.xml, similar results
<?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>
Add a button
1. OpenActivity_my.xml2. In <LinearLayout>, add a <Button> element 3 after <EditText>. Sets the width and height of the button to a property value of"Wrap_content"4. Definition android:text 用来定义button的显示。
Res/layout/activity_my.xml
<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"/> <button android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android : text= "@string/button_send"/></linearlayout>
Fill the input box with the entire screen
The above section, after performing effects such as the following:
Can see that the input box does not fill this screen. Set properties for <EditText>layout_weight and layout_width
<edittext android:layout_weight= "1" android:layout_width= "0dp" ... />
Then take a look ....
[ANDROID5 Series-] 1. Build a simple user interface