程序的运行由主配置文件开始AndroidManifest.xml

 

<?xmlversion="1.0"encoding="utf-8"?>

<manifestxmlns:android="http://schemas.android.com/apk/res/android"

package="com.changcheng.android"

android:versionCode="1"

android:versionName="1.0">

<applicationandroid:icon="@drawable/icon"android:label="@string/app_name">

<activityandroid:name=".HelloWorld"

android:label="@string/app_name">

<intent-filter>

<actionandroid:name="android.intent.action.MAIN"/>

<categoryandroid:name="android.intent.category.LAUNCHER"/>

intent-filter>

activity>

application>

<uses-sdkandroid:minSdkVersion="7"/>

manifest>

 

接下来从HelloWorld类开始:

 

packagecom.changcheng.android;

 

importandroid.app.Activity;

importandroid.os.Bundle;

 

/**

*我们的HelloWorld类,继承自Activity类。

*

*/

publicclassHelloWorldextendsActivity

{

/** Called when the activity is first created. */

@Override

publicvoidonCreate(Bundle savedInstanceState) {

//在此方法中完成界面的绘制

super.onCreate(savedInstanceState);

//显示R.java文件中的layout静态内部类的main常量。它指向mail.xml

setContentView(R.layout.main);

}

}

 

然后再我们再看看mail.xml

 

<?xmlversion="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"

>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

/>

LinearLayout>

 

 

再看看Strings.xml:

 

<?xmlversion="1.0"encoding="utf-8"?>

<resources>

<stringname="hello">HelloWorld,Hello World!string>

resources>

 

现在让我们看看掌管资源的主文件R.java

 

packagecom.changcheng.android;

 

publicfinalclassR {

publicstaticfinalclassattr {

}

//图片资源

publicstaticfinalclassdrawable {

publicstaticfinalinticon=0x7f020000;

}

//界面布局资源

publicstaticfinalclasslayout {

publicstaticfinalintmain=0x7f030000;

}

//字符串资源

publicstaticfinalclassstring {

publicstaticfinalintapp_name=0x7f040001;

publicstaticfinalinthello=0x7f040000;

}

}

R.java文件中的所有资源ID全部是自动生成的,我们不可以手动编辑。当我们添加一个图片时,ADT插件,会以图片的名称为常量的名称,然后自动生成对应的资源ID。当我们向strings.xml中添加一个字符串时,ADT插件会以符串的名称为常量的名称,然后自动生成对应的资源ID

 

R.java文件不需要我们手动编辑,我们只需要在需要使用到资源的地方引用这个文件里标识的资源即可!

 

转自 http://hi.baidu.com/%B3%C1%CF%E3%DC%F8/blog/item/d9d06d3594cfca0890ef39ba.html

更多相关文章

  1. Gallery 画廊
  2. Gallery 画廊
  3. Android学习资源网站
  4. GoogleAndroid常用的Android常量
  5. android Aidl 实现进程间通讯
  6. Android推荐资源
  7. 引用自定义资源需注意数据类型
  8. Android官方入门文档[10]支持不同的屏幕
  9. Android(安卓)绘制资源

随机推荐

  1. android IPC学习
  2. android top弹出框
  3. android 利用httpclient上传图片
  4. android必备知识(一)java引用类型
  5. Android SDK升级后的错误
  6. Android:Animation专题:1.alpha、scale、t
  7. android 实用sax 读取xml文件内容 附源码
  8. 通过tcpdump抓包使用Wireshark --Android
  9. android adb push 与 adb install的比较(
  10. android 终端基本命令