关于android的xml布局文件的id不明白的地方:
有的控件用了系统id,如下红色的代码:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"    
   android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
</TabHost>问题:
为什么需要系统id?有什么好处?不是很理解。id是为了能唯一标识某一控件,如果TabHost有两个呢,都用“@android:id/tabhost”就出问题了啊请教!

解决方案 »

  1.   

    貌似正常情况下,同一个布局文件里不会出现相同的tabhost_ID,
      

  2.   

    并不是非要用系统的ID,如果你写的Activity继承至TabActivity的话,那么你就需要使用系统ID获取当前的标签,如果你当前的Activity界面不仅仅只有标签界面,如还有线性布局,说明标签页只是整个页面一部份的话则可以使用自己定义的ID。
      至于为什么要使用系统ID,是因为继承于TabActivity的窗口时候,基类TabActivity就是通过系统ID索引的
      

  3.   

    那在什么情况下需要用系统id呢?例如我看到的一个例子TextView也加了系统id:
    <TextView android:id="@+id/android:empty"to fff32165:我这有一个例子的xml有两个TabWidget,都用了同样的id,系统id:
    <?xml version="1.0" encoding="utf-8"?>
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@drawable/background">
    <LinearLayout android:orientation="vertical" style="@style/TabStyle"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <TabWidget android:id="@android:id/tabs" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" />
    <TabWidget android:id="@android:id/tabs" android:layout_height="48dp" android:layout_width="match_parent"></TabWidget>
    <FrameLayout android:id="@android:id/tabcontent"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:padding="5dp" >
    </FrameLayout>
    </LinearLayout>
    </TabHost>