Activity Layout Brief
XML- based layouts
Main.xml ( call Project Res/layout/main.xml defined interface element to complete layout display )
|
<?XML version= "1.0"encoding= "Utf-8"?> <LinearLayoutxmlns:Android= "Http://schemas.android.com/apk/res/android" Android: Orientation= "vertical" Android: Layout_width= "Fill_parent" Android: Layout_height= "Fill_parent" ><!--linear layout -- <ImageButton Android: ID= "@+id/button1" Android: Layout_width= "Wrap_content" Android: Layout_height= "Wrap_content" Android: Text= "Wrap_content mode" Android: src= "@drawable/ic_launcher" /><!--to display an image on the button-- <Button Android: ID= "@+id/button2" Android: Layout_width= "Fill_parent" Android: Layout_height= "Fill_parent" Android: Text= "Fill_parent mode" /><!--This button is displayed as Fill_parent mode-- <TextView Android: Layout_width= "Fill_parent" Android: Layout_height= "Wrap_content" Android: Text= "Hello world, myactivity" />
</LinearLayout>
|
based on the layout of the Activity
|
PackageCOM.EXAMPLE.MYAPP1;
Importandroid.app.Activity; ImportAndroid.graphics.Color; ImportAndroid.os.Bundle; ImportAndroid.widget.TextView; //The contents of the activity source files generated by the system are as follows
Public classMyActivityextendsActivity { /** * Called when the activity is first created. */ @Override //means overriding this OnCreate method (using Oncreat () to create the appropriate activity, this method is generally necessary;) The bundle holds the state of the application when it was last closed and can be passed to another activity through one activity Public voidOnCreate (Bundle savedinstancestate) { Super. OnCreate (Savedinstancestate);
TextView tv=NewTextView ( This);
Tv.settext ("Hello");//Set display text Tv.settextsize (48.0f);//Set Font size Tv.settextcolor (Color.BLUE);//Set Font color Setcontentview (TV);The //Statement argument is an instance object name, not an XML layout file
}
}
|
Overview of the Android activity layout