2013-03-06 7 views
8

मुझे आश्चर्य है कि TextView अपनी सामग्री को कई पंक्तियों पर प्रदर्शित करता है without hardcoding the width in the XMLचौड़ाई "wrap_content" के साथ मल्टीलाइन टेक्स्ट व्यू

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="right" 
     android:orientation="horizontal"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:singleLine="false" 
      android:text="Long multiline text"/> 

     <TextView 
      android:textColor="@color/text_color" 
      android:layout_width="130dp" 
      android:layout_height="wrap_content" 
      /> 

    </LinearLayout> 

कोई भी विचार आपका स्वागत है।

संपादित करें: मेरी समस्या यह है कि जब पाठ चौड़ाई सेट से अधिक हो जाता है (क्योंकि यह स्क्रीन के अंत तक पहुंच जाता है) पाठ का एक हिस्सा बस प्रदर्शित नहीं होता है। मैं उम्मीद करता हूं कि पाठ को दो पंक्तियों पर विभाजित किया जाएगा

+1

मैं उलझन में हूँ। जब टेक्स्ट व्यू अपने माता-पिता की चौड़ाई तक पहुंच जाती है, तो एक नई लाइन शुरू होती है। इसके अलावा, _do_ आप लाइनों को तोड़ना चाहते हैं? आप मैन्युअल रूप से लाइन को तोड़ सकते हैं: 'android: text =" long \ nmultiline \ ntext "'। वांछित चौड़ाई तक सामग्री के चारों ओर टेक्स्टव्यू को लपेटने के लिए आप 'maxWidth' विशेषता का भी उपयोग कर सकते हैं। – Sam

+0

आप सही हैं। मैंने अपने प्रश्न को अधिक जानकारी के साथ संपादित किया है – znat

+0

क्या यह 'टेक्स्ट व्यू' का डिफ़ॉल्ट व्यवहार नहीं है? यदि आप 'maxLines' और' सिंगललाइन 'को हटाते हैं तो क्या होता है? – nhaarman

उत्तर

12

हालांकि मैं लपेटने की समस्या को पुन: उत्पन्न नहीं कर सकता, फिर भी आप का उपयोग करके TextView पर स्थिति समस्या को ठीक कर सकते हैं। निम्नलिखित XML का उपयोग चित्रमय लेआउट दृश्य में उम्मीद उत्पादन देता ग्रहण में:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="right" 
    android:orientation="horizontal"> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:singleLine="false" 
     android:text="Long multiline text"/> 

    <TextView 
     android:textColor="@color/text_color" 
     android:layout_width="130dp" 
     android:layout_height="wrap_content" 
     /> 

</LinearLayout> 
+0

धन्यवाद निक, वह था। – znat

+0

क्या हास्यास्पद बग! – shimatai

+0

एंड्रॉइड: सिंगललाइन अब बहिष्कृत है –

1

आप

android:inputType="textMultiLine" 
अपने TextView एक्सएमएल में

की कोशिश कर सकते। यह मेरे लिए काम किया।

1

इसके अलावा आप क्या चाहते से जोड़ने

android:minLines="2" 
android:scrollHorizontally="false" 
संबंधित मुद्दे