Android 中的组件需要用一个int 类型的值来表示,这个值也就是组件标签中的id 属性值。id 属性只能接受资源类型的值,也就是必须以 @ 开头的值,例如,@id/abc@+id/xyz等。
      如果在@后面使用+,表示当修改完某个布局文件并保存后,系统会自动在R.java文件中生成相应的 int类型变量。变量名就是 / 后面的值,例如,@+id/xyz会在 R.java 文件中生成int xyz = value,其中value是一个十六进制的数。如果 xyzR.java中已经存在同名的变量,就不再生成新的变量,而该组件会使用这个已存在的变量的值。
      既然组件的 id属性是一个资源id就可以,那么自然可以设置任何已经存在的资源id值,例如,@drawable/icon@string/ok@+string/you。当然,也可以设置 android 系统中已存在的资源 id,例如,楼主提出的 @id/android:list,那么这个 android 是什么意思呢,实际上,这个 android 就是系统的R 类(在R.java文件中)所在的 package 。我们可以在 Java 代码编辑区输入android.R.id.,就会列出相应的资源 id,例如,也可以设置id属性值为@id/android:message

<ListView  android:id="@+id/android:message" android:layout_width="wrap_content" android:layout_height="wrap_content"/>

还有另外一种方法查看系统中定义的 id
进入

<?xml version="1.0" encoding="utf-8"?><resources>    <item type="id"name="price_edit">falseitem>    <item type="id"name="amount_edit">falseitem>resources>

若在 ids.xml中定义了Id,则在layout中可如下定义@id/price_edit,否则@+id/price_edit

即是说当我们第一次定义一个控件的 id 时,我们需要使用 @+id/xxx,而当我们使用这个 id 时可以使用 @id/xx 的形式,如下可以看到 iv_userhead

<RelativeLayout  android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp">        <ImageView  android:id="@+id/iv_userhead" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:focusable="false" android:src="@drawable/ic_chat_head"/>        <TextView  android:id="@+id/tv_chatcontent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="10dp" android:layout_centerVertical="true" android:layout_toEndOf="@id/iv_userhead" android:padding="10dp" android:background="@drawable/sh_chat_bg_msg_from" android:textSize="14sp"/>    RelativeLayout>

更多相关文章

  1. android中,实现水平方向上三个按钮左对齐、居中对齐、右对齐效果
  2. Android属性动画、函数动画
  3. android中focusable和focusableInTouchMode
  4. 关于Android中的Intent一点说明
  5. 高效android编程
  6. 34、Android编写应用-从模板添加代码
  7. Android模拟开关按钮点击打开动画(属性动画之平移动画)
  8. 安居客Android项目架构演进
  9. tools:text和android:text

随机推荐

  1. SmartFoxServer: massive multiplayer ga
  2. androidStudio没有httpclient的解决办法
  3. android 常用的数据库表以及操作说明
  4. 《Android开发从零开始》——2.模拟器的
  5. 安卓5.1屏蔽recent_apps
  6. Android(安卓)TextSwitcher通知公告自动
  7. android通讯录根据手机号码查询姓名
  8. android 一键锁屏
  9. android xml 解析 修改
  10. android使用自定义属性