Android中是否有自定义XML样式属性的文档标准?

时间:2014-05-13 21:08:12

标签: java android xml javadoc documentation-generation

我能够在Android项目中记录几乎所有内容,并为它们生成漂亮的API参考。

唯一的例外是XML文件,尤其是包含可样式属性的属性文件。

例如, res / values / attrs.xml 的一部分:

<resources>
    <declare-styleable name="TimelineView">
        <attr name="drawCollapsed" format="boolean" />
    </declare-styleable>
</resources>

我注意到在Android源代码中standard attributes documentation is generated for R

我生成的文档显然包含了我的属性类型的一些通用文本(在本例中为boolean):

auto-documented property

是否有此类文档的官方规范或记录源自XML的属性的方式,以便描述出现在自动生成的JavaDoc中?

1 个答案:

答案 0 :(得分:17)

我不确定这是一个官方标准,但在写我的问题时我偶然发现了它。无论如何,为了可能遇到这个问题的其他人,我决定发布问题并回答它。

我能够通过在属性上方添加XML注释来生成属性文档,现在我已经看到它了,这似乎很明显。

我最初尝试过而没有重建我的项目,导致原来缺乏文档。一旦我重建了模块并生成了JavaDoc,我就得到了理想的结果。

要遵循的步骤是:

  1. 在所需属性上方添加评论。

    <resources>
        <declare-styleable name="TimelineView">
            <!-- Initially draw collapsed until adapters have been set. -->
            <attr name="drawCollapsed" format="boolean" />
        </declare-styleable>
    
    </resources>
    

  2. 重建相关模块/项目。

  3. 生成JavaDoc。使用Android Studio(目前为0.5.8) 目前有small issue自动生成,我正在使用第一个链接帖子中介绍的解决方法 生成的文档应包含您的评论 desired documentation
  4. 如果有人知道任何官方消息来源或官方方法,请不要犹豫与他人分享。

    <强>更新
    看来这确实是在Android source files中完成的方式,包括注释中的一些JavaDoc指令,HTML和子注释,例如:

    <!-- Alignment constants. -->
    <attr name="alignmentMode">
        <!-- Align the bounds of the children.
        See {@link android.widget.GridLayout#ALIGN_BOUNDS}. -->
        <enum name="alignBounds" value="0" />
        <!-- Align the margins of the children.
        See {@link android.widget.GridLayout#ALIGN_MARGINS}. -->
        <enum name="alignMargins" value="1" />
    </attr>