2013-03-27 57 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