android:id="@+id/btn",表示在R.java文件里面新增一个id为btn的控件索引,最常用的一种声明控件id的方式。android:id="@android:id/tabhost",表示引用的是系统已有的ID,在对应的sdk目录下的ids.xml里面。一般外部不去调用,是组件内部调用的时候使用。.android:id="@id/btn",表示引用一个已经存在的ID,在R.java里面的,比如我们自己建了一个ids.xml,里面声明了一组id,其中一个是btn,那么你就可以这样引用了。

许多UI开发的同学会对 android:id="@+id/my_button"的含义有所疑问,细心的同学会发现官方SDK是这样解释的,

The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource. The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in theR.javafile). There are a number of other ID resources that are offered by the Android framework. When referencing an Android resource ID, you do not need the plus-symbol, but must add theandroidpackage namespace, like so:

android:id="@android:id/empty"

意思也就是说 @符号要通知xml要转换@后面的字符串为ID资源,而+号表示这是要创建一个新的资源名字,并且添加到R.java文件中。

当你要引用已有的资源的时候 可以直接写成 @android:id/empty

更多相关文章

  1. linux mint 17编译android 2.3.1错误记录
  2. Android(安卓)ScrollView 内部控件 layout_margin失效的解决方法
  3. Error while executing process D:\Android\SDK\android-sdk-
  4. android 里面的测量单位
  5. android引用外部工程或jar包
  6. android中context
  7. Android常用第三方框架
  8. android中context
  9. android am命令

随机推荐

  1. Android Web App官方文档翻译第一章:概览
  2. Android UI--ViewPager扩展Tab标签指示
  3. cocos2d-x 源码剖析(15)
  4. 框架模式MVP在Android中的使用
  5. 漫谈anroid软件设计中的contentprovider
  6. 系统移植之为Android启动加速
  7. Android中的IntentService解析
  8. Android 弧形列表转盘的实现(三),View跟随Re
  9. Android自定义View的基本步骤和使用自定
  10. android使用ImageView加载本地SdCard图片