工程目录结构:
HelloWorldActivity.java程序清单
- package com.oristand;
- import android.app.Activity;
- import android.os.Bundle;
- public class HelloWorldActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);//到layout目录下会对应一个main.xml配置文件,改文件决定了你要使用的那些组件,以及组件的属性,比如TextView、EditText、Button等
- }
- }
package com.oristand;
import android.app.Activity;
import android.os.Bundle;
public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);//到layout目录下会对应一个main.xml配置文件,改文件决定了你要使用的那些组件,以及组件的属性,比如TextView、EditText、Button等
}
}
main.xml程序清单
- <?xml version= "1.0" encoding= "utf-8" ?>
- <TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/hello_world" android:layout_width= "fill_parent"
- android:layout_height="fill_parent" android:gravity= "center_vertical|center_horizontal"
- android:text="@string/hello_world" />
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/hello_world" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical|center_horizontal" android:text="@string/hello_world" />
R.java程序清单 —— res目录下的任何一个配置修改后,该文件会自动修改,这就是mvc模式的好处,一旦model修改,view也相应的改变,这就是mvc的优势
- package com.oristand;
- public final class R {
- public static final class attr {
- }
- public static final class drawable {
- public static final int icon=0x7f020000 ;
- }
- public static final class id {
- public static final int hello_world=0x7f050000 ;
- }
- public static final class layout {
- public static final int main=0x7f030000 ;
- }
- public static final class string {
- public static final int app_name=0x7f040001 ;
- public static final int hello_world=0x7f040000 ;
- }
- }
package com.oristand;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int hello_world=0x7f050000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello_world=0x7f040000;
}
}
string.xml程序清单
- <?xml version= "1.0" encoding= "utf-8" ?>
- <resources>
- <string name="hello_world" >Hello World!</string>
- <string name="app_name" >HelloWorldDemo</string>
- </resources>
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello_world">Hello World!</string> <string name="app_name">HelloWorldDemo</string> </resources>
AndroidManifest.xml程序清单
- <?xml version= "1.0" encoding= "utf-8" ?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.oristand"
- android:versionCode="1"
- android:versionName="1.0.0" >
- <application android:icon="@drawable/icon" android:label= "@string/app_name" >
- <activity android:name=".HelloWorldActivity"
- android:label="@string/app_name" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.oristand" android:versionCode="1" android:versionName="1.0.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".HelloWorldActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
运行配置
运行结果: