2013-03-27 56 views
4

什麼是這個Android代碼的含義?什麼是星號(*)指的是Android的XML資源時的含義是什麼?

是什麼*+與空之間的區別:/佈局

<TextView android:id="@*android:id/timeDisplayForeground" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:singleLine="true" 
    android:ellipsize="none" 
    android:textSize="@dimen/crypt_clock_size" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:textColor="@color/crypt_keeper_clock_foreground" 
    android:layout_alignLeft="@*android:id/timeDisplayBackground" 
    android:layout_alignTop="@*android:id/timeDisplayBackground" 
    android:layout_marginBottom="6dip" /> 
+0

看到這個問題: http://stackoverflow.com/questions/5685456/is-there-any-way-to-use-not-public-android-resources-in-my-application – satur9nine 2013-03-27 01:25:04

回答

4

的*允許您訪問私有資源。私人資源是私人的,因爲他們的名字將來可能會作爲固件或皮膚更新的一部分而改變。

這不是利用這些資源,除非你在你知道這些資源不會改變,在未來打破你的應用的環境正在處理一個好主意。

在你的榜樣,私人資源正在由系統應用程序,它是在那裏你會最常看到這個引用*使用引用。

+0

順便說一句。我可以在SDK環境中使用代碼,以及如何去做。感謝 – 2013-03-27 02:16:52

+0

您可以在SDK開發環境使用,但它更可取的,你複製你需要的資源和本地引用它們。 – MCeley 2013-03-27 02:45:10

1

我剛纔回答了,但可能有誤解

@*android:id 

像這樣android_ics /封裝/應用/設置/ RES你的問題。您的項目中有一個名爲R.java的生成文件,其中列出了您的資源。例如,當您創建視圖,並添加按鈕,你會看到其中的一些信息進入你的R.java文件自動。在Java中,您可以使用這些成員訪問信息。但是,在XML中,您必須通過引用標籤或節點來訪問它們。

@android:id refers to the public system member called "id" 
@id refers to one that you've created 
@+id says to create one called "id" (and what to set it to) 
@*android:id refers to a private system member 

參考:http://developer.android.com/training/basics/firstapp/building-ui.html