活动布局:片段类:VS机器人:名称属性 [英] Activity Layout: Fragment class: vs android:name attributes

查看:125
本文介绍了活动布局:片段类:VS机器人:名称属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过有关片段的文档的Andr​​oid开发者指南中,我已经可见,有时他们指定的类实例化的片段标记属性的安卓名称的和某个他们使用的类:的属性:

I've read the documentation about Fragments in the Android Developer Guide and I've seen that sometimes they specify the class to instantiate with the Fragment tag attribute android:name and sometime they use the class: attribute:

<fragment
    android:name="com.example.news.ArticleReaderFragment"
    android:id="@+id/viewer"
    android:layout_weight="2"
    android:layout_width="0dp"
    android:layout_height="match_parent" />

<fragment
    class="com.example.android.apis.app.FragmentLayout$TitlesFragment"
    android:id="@+id/titles" 
    android:layout_weight="1"
    android:layout_width="0px" 
    android:layout_height="match_parent" />

安卓名称类:的互换?如果我使用Eclipse中的自动完成功能,他们都表现出同样的文件头(即属性提供的类名被实例化)。也许您必须使用第二个时要实例化的类具有从Java文件名称不同,例如,一个名称的 TitlesFragment 的是在 FragmentLayout.java 的文件吗?或者,我可以使用语法的 package.fileDOTjava $类的也用的安卓:名称的属性

Are android:name and class: interchangeable? If I use the autocompletion function in Eclipse, they both show the same documentation tip (i.e. the attribute provides the class name to be instantiated). Maybe you must use the second one when the class to be instantiated has a name which is different from the java file name, like TitlesFragment which is in the FragmentLayout.java file? Or can I use the syntax package.fileDOTjava$Class also with the android:name attribute?

我想有一些文档的XML标记和属性作为Android的Java类(我已经在另一个问一下吧问题)。

I'd like to have some documentation for XML tags and attributes as for Android Java Classes (I've asked about it in another question).

推荐答案

由于Activity.onCreateView源说:

As Activity.onCreateView source says:

String fname = attrs.getAttributeValue(null, "class");
TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Fragment);
if (fname == null) {
    fname = a.getString(com.android.internal.R.styleable.Fragment_name);
}

这似乎意味着,节目看起来class属性第一。而就失败看起来name属性。 因此,只要其使用阶级,如果更有效的是真的。

That seemingly means that program looks "class" attribute first. And on fail looks "name" attribute. So as far as it's true using "class" if more efficient.

这篇关于活动布局:片段类:VS机器人:名称属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆