2016-07-30 81 views
2

在以下XML中,對元素屬性發表評論的替代方法是什麼?XML內部元素

<!-- I can comment here --> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/textView_ben" 

     <!-- Cannot place a comment here --> 

     android:layout_centerHorizontal="true"/> 
+1

請參閱http://stackoverflow.com/questions/26461869/how-to-comment-attributes-inside-xml-tag – DAB

回答

1

註釋只能前或開始標記(無論它是一個空的標籤)後出現。

註釋可以出現內的XML元素的start-tag

[40] STag ::= '<' Name (S Attribute)* S? '>'

也可以評論出現結束標籤內:

[44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'

一般來說,每節2.5 Comments

[定義:評論可以對一文件中的任何地方出現外 其他markup;此外,它們可能會出現在文檔允許的地方 類型聲明中。 ...]


這裏是記錄元件的一種方法屬性:

<TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/textView_ben" 
     android:layout_centerHorizontal="true"/> 
    <!-- 
     android:id="@+id/textView_ben" 
      addresses defect #123 
     android:layout_centerHorizontal="true" 
      blah blah blah --> 

可替換地,這樣的註釋可能標記之前出現;它只能在之內出現一個標籤。