用反射动态获取资源ID

1.用反射:

        Field field=R.layout.class.getField("main");
        int i= field.getInt(new R.layout());

2.用Resources: 
        Resources res=getResources();
        int i = res.getIdentifier("main","layout",getPackageName());

你可能感兴趣的:(layout,resources)