Building a simple User Interface
The graphical user interface for an Android app is built using a hierarchy of
the graphical user interface for an Android app is built using a hierarchy Of view
and View
objects is usually UI widgets such as buttons or text fields and viewgroup
objects is invisible view containers that define what the child views is laid out, such as in a GR ID or a vertical list.
Android provides an XML vocabulary this corresponds to the subclasses of and so you View
ViewGroup
can define your UI in XML Using a hierarchy of UI elements.
Alternative Layouts
Declaring your UI layout in XML rather than runtime code was useful for several reasons, but it's especially important so Y ou can create different layouts for different screen sizes. For example, you can create the versions of a layout and tell the system to use one on "small" screens and the other on "L Arge "screens. For more information, see the class about supporting Different Devices.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/54/52/wKiom1R_AlCRL5g1AAB6WUBhkqk844.jpg "title=" Viewgroup.png "alt=" Wkiom1r_alcrl5g1aab6wubhkqk844.jpg "/>
This paragraph is mainly said that we use the TextView Ah, button Ah, they are view, we see the view is shown on the ViewGroup, ViewGroup is not visible. There is a hierarchical relationship between view and ViewGroup, and ViewGroup is the container for view.
We can create XML files under/layout/to directly show these TextView, buttons, and so on, because they are all sub-classes of view. LinearLayout is a subclass of ViewGroup.
Next we write a edittext that describes the various properties in the view.
Id,layout_height,layout_width,hint
Use of strings resources
wrote a button and then described how to make a edittext and button on a line in the LinearLayout layout.
The main use is layout_weight this property, all the view default Layout_weight value is 0, as long as the specified layout_weight is greater than 0, then the view will be stained with the remaining space. If you set the two view weight to 1 and set Layout_width to 0, then two view split space.
Starting another Activity
First define a button in XML, add the OnClick property, the value of the OnClick property is the method name in acitvity, such as tosecondactivity, where you use this button to jump to another activity and bring the data.
In activity, the button defines the method as
public void tosecondactivity (View v) {
1. The method is public 2. The return value is void 3. The parameter is view.
Intent Intent = new Intent (this,secondactivity.class);
String message = Edittext.gettext (). toString (). Trim ();
Intent.putextra (Extra_message,message);
StartActivity (Intent);
}
Add a new secondactivity in Manifest.xml
The intent Putextra () method passes the data in Value-key way.
When you click on the button, you'll jump to the second activity.
The way to start activity belongs to Intent's display jump activity.
Get information in the second activity and show:
@Override
Public voidonCreate(Bundlesavedinstancestate) {
Super.onCreate(savedinstancestate);
//Get The message from the intent
IntentIntent=getintent();
Stringmessage=Intent.Getstringextra(mainactivity.Extra_message);
//Create The text view
TextViewTextView= New TextView( This);
TextView.settextsize( +);
TextView.SetText(message);
//Set The text view as the activity layout
Setcontentview(TextView);
}
This article is from "Jack's Footsteps" blog, make sure to keep this source http://jack326162646.blog.51cto.com/7640742/1586096
Android official tutorial from zero opener (ii)