मैं कुछ टिप्पणियों को लेआउट XML फ़ाइलों में दर्ज करना चाहूंगा, मैं यह कैसे करूंगा?
मैं कुछ टिप्पणियों को लेआउट XML फ़ाइलों में दर्ज करना चाहूंगा, मैं यह कैसे करूंगा?
जवाबों:
जैसा कि अन्य ने कहा, एक्सएमएल में टिप्पणी इस तरह से है
<!-- this is a comment -->
ध्यान दें कि वे कई लाइनों पर हो सकते हैं
<!--
This is a comment
on multiple lines
-->
लेकिन वे नेस्टेड नहीं हो सकते
<!-- This <!-- is a comment --> This is not -->
इसके अलावा, आप उन्हें टैग के अंदर उपयोग नहीं कर सकते
<EditText <!--This is not valid--> android:layout_width="fill_parent" />
वर्ल्ड वाइड वेब कंसोर्टियम (W3C) ने वास्तव में एक टिप्पणी इंटरफ़ेस को परिभाषित किया। परिभाषा कहती है all the characters between the starting ' <!--' and ending '-->' form a part of comment content and no lexical check is done on the content of a comment।
अधिक विवरण developer.android.com साइट पर उपलब्ध हैं ।
तो आप बस किसी भी शुरुआती और समाप्त टैग के बीच अपनी टिप्पणी जोड़ सकते हैं। ग्रहण आईडीई में बस टाइप <!--करना आपके लिए टिप्पणी को पूरा करेगा। फिर आप बीच में अपना टिप्पणी पाठ जोड़ सकते हैं।
उदाहरण के लिए:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".TicTacToe" >
<!-- This is a comment -->
</LinearLayout>
विशेष रूप से उल्लेख करने in betweenका उद्देश्य है क्योंकि आप इसे एक टैग के अंदर उपयोग नहीं कर सकते।
उदाहरण के लिए:
<TextView
android:text="@string/game_title"
<!-- This is a comment -->
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
गलत है और निम्नलिखित त्रुटि देगा
Element type "TextView" must be followed by either attribute specifications, ">" or "/>".
ctrl + shift + / आप कोड को कमेंट कर सकते हैं।
<!--
<View
android:layout_marginTop="@dimen/d10dp"
android:id="@+id/view1"
android:layout_below="@+id/tv_change_password"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#c0c0c0"/>-->
<!-- comment here -->
कस्टम विशेषताएँ बनाना संभव है जिनका उपयोग टिप्पणी / प्रलेखन उद्देश्यों के लिए किया जा सकता है।
नीचे दिए गए उदाहरण में, एक documentation:infoविशेषता को परिभाषित किया गया है, उदाहरण टिप्पणी मूल्य के साथ:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:documentation="documentation.mycompany.com"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/relLayoutID"
documentation:info="This is an example comment" >
<TextView
documentation:purpose="Instructions label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click here to begin."
android:id="@+id/tvMyLabel"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
documentation:info="Another example comment"
documentation:translation_notes="This control should use the fewest characters possible, as space is limited"
/>
</RelativeLayout>
ध्यान दें कि इस मामले में, documentation.mycompany.comनए कस्टम XML नाम स्थान ( documentation) के लिए सिर्फ एक परिभाषा है , और इस प्रकार यह केवल एक अद्वितीय URI स्ट्रिंग है - जब तक यह अद्वितीय है तब तक यह कुछ भी हो सकता है। कैन documentationके दाईं ओर xmlns:भी कुछ भी हो सकता है - यह उसी तरह से काम करता है जैसे android:XML नाम स्थान परिभाषित और उपयोग किया जाता है।
इस प्रारूप का उपयोग करते हुए, किसी भी संख्या के गुण बनाए जा सकते हैं, जैसे कि documentation:info, documentation:translation_notesआदि, एक विवरण मान के साथ, प्रारूप किसी भी XML विशेषता के समान है।
संक्षेप में:
xmls:my_new_namespaceXML लेआउट फ़ाइल में रूट (शीर्ष-स्तरीय) XML तत्व के लिए एक विशेषता जोड़ें । इसके मूल्य को एक अद्वितीय स्ट्रिंग पर सेट करें<TextView my_new_namespace:my_new_doc_property="description" />tools:इसके बजाय विशेष नाम स्थान का उपयोग करने पर विचार करें , जो छूट जाता है। (यह उत्तर मौजूद होने पर संभवतः मौजूद नहीं था, लेकिन इस पृष्ठ को नए दर्शक
यदि आप Android Studioकेवल प्रेस में टिप्पणी करना चाहते हैं :
Ctrl/विंडोज / लिनक्स पर +
Cmd+ /मैक पर।
यह XML फ़ाइलों के strings.xmlसाथ-साथ कोड फ़ाइलों में भी काम करता है MainActivity.java।
आप Ctrl + Shift + / और Shift + / एक पंक्ति दबाकर टिप्पणी भी जोड़ सकते हैं।
अविश्वसनीय रूप से, 2019 में एंड्रॉइड स्टूडियो 3.3 के साथ (मुझे सटीक संस्करण नहीं पता है, कम से कम 3.3), xml पर डबल स्लैश टिप्पणी का उपयोग करना संभव है।
लेकिन अगर आप xml में डबल स्लैश टिप्पणी का उपयोग करते हैं, तो IDE चेतावनी दिखाता है।
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
// this works
/* this works too */
/*
multi line comment
multi line comment
*/
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World! yeah"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Unexpected text found in layout file: ...।
फेडेरिको कुल्लोक के नोट से:
इसके अलावा, आप उन्हें टैग के अंदर उपयोग नहीं कर सकते
माध्यम; आपको फ़ाइल के ऊपर या नीचे टिप्पणी डालनी होगी - वे सभी स्थान जिन्हें आप वास्तव में टिप्पणी जोड़ना चाहते हैं, कम से कम शीर्ष स्तर के लेआउट टैग के अंदर हैं