1
<
TextView
2
android:id
="@+id/noteInfo"
3
android:layout_width
="match_parent"
4
android:layout_height
="wrap_content"
5
/>
Android布局文件中的组件被调用时需要定义组件的 android:id属性,android:id属性只能接受资源类型的值,就是必须以@开头的值。在android:id属性值里面有@id/和@+id/两种。那么这两种方式有什么区别呢?
最初学习Android的时候我们大多用@+id/这种方式来定义一个组件的id属性,当我们保存布局文件后,系统会自动的在R.java中生成一个int类型的16进制值的变量。public static final int noteInfo=0x7f070007;这时如果我们再定义另一个组件的android:id="@+id/noteInfo",则该组件会使用同一个变量值,不会再自动生成。
1 < FrameLayout 2 android:id ="@android:id/tabcontent" 3 android:layout_width ="fill_parent" 4 android:layout_height ="fill_parent" >
另一种方式是使用@id/或者@android:id/,这种方式定义的id是直接引用系统已经定义好的值。例如我们使用TabHost组件的时候。
1 <? xml version="1.0" encoding="utf-8" ?> 2 < TabHost xmlns:android ="http://schemas.android.com/apk/res/android" 3 android:id ="@android:id/tabhost" 4 android:layout_width ="fill_parent" 5 android:layout_height ="fill_parent" > 6 7 < LinearLayout 8 android:orientation ="vertical" 9 android:layout_width ="fill_parent" 10 android:layout_height ="fill_parent" > 11 < TabWidget 12 android:id ="@android:id/tabs" 13 android:layout_width ="fill_parent" 14 android:layout_height ="wrap_content" /> 15 < FrameLayout 16 android:id ="@android:id/tabcontent" 17 android:layout_width ="fill_parent" 18 android:layout_height ="fill_parent" > 19 ... 20 </ FrameLayout > 21 </ LinearLayout > 22 23 </ TabHost >
TabHost的id必须是tabHost,TabWidget的id必须是tabs,FrameLayout的id必须是tabcontent。这些id都是直接引用的系统的值。
根据这种思路,我们完全可以自己定义一个ids.xml用来封装我们自己定义的所有组件的id。ids.xml的使用以后我会专门介绍。
Android布局文件中的组件被调用时需要定义组件的 android:id属性,android:id属性只能接受资源类型的值,就是必须以@开头的值。在android:id属性值里面有@id/和@+id/两种。那么这两种方式有什么区别呢?
最初学习Android的时候我们大多用@+id/这种方式来定义一个组件的id属性,当我们保存布局文件后,系统会自动的在R.java中生成一个int类型的16进制值的变量。public static final int noteInfo=0x7f070007;这时如果我们再定义另一个组件的android:id="@+id/noteInfo",则该组件会使用同一个变量值,不会再自动生成。
1 < FrameLayout 2 android:id ="@android:id/tabcontent" 3 android:layout_width ="fill_parent" 4 android:layout_height ="fill_parent" >
另一种方式是使用@id/或者@android:id/,这种方式定义的id是直接引用系统已经定义好的值。例如我们使用TabHost组件的时候。

1 <? xml version="1.0" encoding="utf-8" ?> 2 < TabHost xmlns:android ="http://schemas.android.com/apk/res/android" 3 android:id ="@android:id/tabhost" 4 android:layout_width ="fill_parent" 5 android:layout_height ="fill_parent" > 6 7 < LinearLayout 8 android:orientation ="vertical" 9 android:layout_width ="fill_parent" 10 android:layout_height ="fill_parent" > 11 < TabWidget 12 android:id ="@android:id/tabs" 13 android:layout_width ="fill_parent" 14 android:layout_height ="wrap_content" /> 15 < FrameLayout 16 android:id ="@android:id/tabcontent" 17 android:layout_width ="fill_parent" 18 android:layout_height ="fill_parent" > 19 ... 20 </ FrameLayout > 21 </ LinearLayout > 22 23 </ TabHost >
TabHost的id必须是tabHost,TabWidget的id必须是tabs,FrameLayout的id必须是tabcontent。这些id都是直接引用的系统的值。
根据这种思路,我们完全可以自己定义一个ids.xml用来封装我们自己定义的所有组件的id。ids.xml的使用以后我会专门介绍。