First, let's talk about how to create an activity:
/** Key points for creating an activity * 1. an activity is a class, which must inherit from activity * 2. the oncreate Method * 3 needs to be rewritten. every activity must be in androidmainifest. configure in XML file * 4. add necessary controls for the activity **/
Step 2 creates a button control and a textview control for the activity.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/myTextView" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:id="@+id/myButton" android:layout_width="fill_parent" android:layout_height="wrap_content"/></LinearLayout>
At the same time, modify the relative layout (relativelayout) of the created project to a relatively simple linear layout (linearlayout ).
In addition, there are five layout methods for Android:
Framelayout (Framework layout), linearlayout (linear layout), absolutelayout (absolute layout), relativelayout (relative layout), tablelayout (table layout)
Return to the Java code, in the oncreate () method:
@ Override public void oncreate (bundle savedinstancestate) {// call the oncreate () method super in the parent class. oncreate (savedinstancestate); // sets the layout file setcontentview (R. layout. activity_main); // the return value of the following function is view, and view is the parent class textview mytextview = (textview) findviewbyid (R. id. mytextview); button mybutton = (button) findviewbyid (R. id. mybutton); mytextview. settext ("first textview"); mybutton. settext ("first button ");}
Note:
import android.widget.Button;import android.widget.TextView;
OK, running effect:
Work hard every day. Come on!
Bytes ------------------------------------------------------------------------------------------
Author: PANG Hui
Source: http://www.cnblogs.com/pang123hui/
This article is based on the signature 2.5 mainland China license agreement. You are welcome to repost, interpret, or use it for commercial purposes. However, you must keep the signature Pang Hui (including the link) of this Article ).