0. Project structure
A simple Android project structure is roughly as follows
The entrance is mainactivity this class, if for an unfamiliar project, the best way is to see Androidmainifest.xml, as follows
<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Activitytest.example.com.firstactivity"> <ApplicationAndroid:allowbackup= "true"Android:icon= "@mipmap/ic_launcher"Android:label= "@string/app_name"Android:supportsrtl= "true"Android:theme= "@style/apptheme"> <ActivityAndroid:name=". Mainactivity "Android:label= "@string/app_name"Android:theme= "@style/apptheme.noactionbar"> <Intent-filter> <ActionAndroid:name= "Android.intent.action.MAIN" /> <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> </Intent-filter> </Activity> </Application></Manifest>
You can see that Android:name is. Mainactivity, from Androidmainifest.xml can see that the project has only one activity, the entrance of the activity is mainactivity.
1. Project structure
Through activity, it is easy to find the corresponding project structure.
@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Requestwindowfeature (Window.feature_no_title); Setcontentview (R.layout.activity_main); FinalButton Button =(Button) Findviewbyid (r.id.button_1); FinalButton Button_finish =(Button) Findviewbyid (r.id.button_finish); Button.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {toast.maketext (mainactivity. This, "You touch This button", Toast.length_long). Show (); } }); Button_finish.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {finish (); } });
Enter Mainactivity, find the OnCreate method, which is the first method that the activity calls, Setcontentview (R.layout.activity_main) can load a layout for the activity, The reference to static resources here is activity_main.xml, note that the R object, which can call the Res folder below the resources.
Activity_main.xml is the equivalent of V in MVC, let's see what it looks like.
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" > <ButtonAndroid:id= "@+id/button_1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Alex" /> <ButtonAndroid:id= "@+id/button_finish"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Finish"/></LinearLayout>
With the components you add yourself, you can display them in the layout of your activity.
Android first line code-1. Project structure