添加库项目时将android R.java映射到资源布局 [英] android R.java mapping to resource layouts when a library project is added
问题描述
我在以下位置对我的问题进行了一些研究 Android R.java在库时的行为项目已添加
I did some research on my question at android R.java behavior when a library project is added
我观察到,将库项目添加到任何android项目时,都会创建两个R.java文件.
I observe that when a library project is added to any android project, there are two R.java files created.
project.R.java
project.R.java
public static final class layout {
public static int capture=0x7f030000;
public static int main=0x7f030001;
}
lib.R.java
lib.R.java
public static final class layout {
public static final int add=0x7f030000;
public static final int capture=0x7f030001;
public static final int main=0x7f030002;
}
并且被设置为库的项目具有自己的R.java,看起来像
and the project which was set as library has its own R.java which looks like
public static final class layout {
public static int capture=0x7f030000;
public static int main=0x7f030001;
}
示例库只有一个活动,我是从我的应用程序开始的,该活动设置了版面主要.现在,如果我们在应用程序和库项目中看到R.java中"main"的id不同.我试图从库中打印id的值,并给出0x7f030002,这是我的应用程序R.java文件中的值.
The sample library has just one activity which i am starting from my application and this activity sets the layout main. Now if we see that id for "main" in R.java is different in my application and in the library project. I tried to print the value of id from library and its giving 0x7f030002 which is the value in my application R.java file.
现在,当我将内容设置为smain时,我的应用程序没有主布局,并且在库中,它从库项目中设置了main.xml!如果我将主布局添加到我的应用程序项目中,则lib将把这个主布局设置为其布局!!
Now my application has no main layout and in library when i set content a smain , its setting the main.xml from library project !! If i add main layout to my application project, the lib will set this main as its layout !!
即main的id是从我的应用程序的R.java中获取的,此id与库中main的id不同,但布局是从库中正确选择的.
Ie the id for main is taken from R.java of my application and this id is different from the id for main in the library but the layout is correctly picked from library.
这是怎么回事请帮助
我的应用活动:
import com.idg.test.lib.TestLibActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
public class TestProjectActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i("starting","oncraete main id "+ R.layout.main);
super.onCreate(savedInstanceState);
setContentView(R.layout.add);
startActivity(new Intent(this,TestLibActivity.class));
}
}
lib活动:
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class TestLibActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("Library","Library main id" +R.layout.main );
setContentView(R.layout.main);
}
}