2011-12-06 12 views
23

मैं एक छोटा एंड्रॉइड ऐप विकसित कर रहा हूं, और मुझे लेआउट के साथ समस्या हो रही है, मैं अपने एक्सएमएल में त्रुटि खोजने की कोशिश कर रहा हूं, लेकिन मुझे यह नहीं मिला ...लेआउट परिभाषा। "आपको एक लेआउट_विड्थ विशेषता प्रदान करनी होगी।"

त्रुटि I 'm हो रही है "आप एक layout_width विशेषता प्रदान करना होगा", लेकिन मैं इसे किया है और यह अभी भी काम नहीं करता है ...

यहाँ मेरी एक्सएमएल फ़ाइल है:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="100" > 

    <TextView android:id="@+id/nombreEvento" 
     android:layout_height="fill_parent" 
     android:layout_weight="70" 
    /> 

    <TextView android:id="@+id/moneda" 
     android:layout_height="fill_parent" 
     android:layout_weight="10" 
    /> 

    <TextView android:id="@+id/totalEvento" 
     android:layout_height="wrap_content" 
     android:layout_weight="20" 
    /> 
    </LinearLayout> 

<TextView android:id="@+id/fecha" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
/> 

</LinearLayout> 

उत्तर

18

नहीं अपने TextViews के सभी layout_height है और layout_height के बजाय layout_weight और layout_width (और संभवतः layout_weight)। इसे आज़माएं:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="100" > 

    <TextView android:id="@+id/nombreEvento" 
     android:layout_height="fill_parent" 
     android:layout_width="0dp" 
     android:layout_weight="70" 
    /> 

    <TextView android:id="@+id/moneda" 
     android:layout_height="fill_parent" 
     android:layout_width="0dp" 
     android:layout_weight="10" 
    /> 

    <TextView android:id="@+id/totalEvento" 
     android:layout_height="wrap_content" 
     android:layout_width="0dp" 
     android:layout_weight="20" 
    /> 
    </LinearLayout> 

<TextView android:id="@+id/fecha" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
/> 

</LinearLayout> 
+2

का उपयोग क्या अंतर है? –

+1

@ AlikElzin-kilaka नेस्टेड टेक्स्ट दृश्यों में layout_WEIGHT है ... लेआउट_WIDTH भी होना चाहिए। – ComeIn

2

आप चौड़ाई specifiy करने की जरूरत है और दृश्य की ऊंचाई। यह एक जरूरी है। टेक्स्टव्यू के लिए, आप केवल ऊंचाई और वजन निर्धारित कर रहे हैं। जोड़े

android:layout_width="0dip" 
3

android:layout_width="wrap_content" को अपने टेक्स्ट व्यू में जोड़ने का प्रयास करें, जिसमें यह नहीं है।

+0

मैं हर समय इसका उपयोग करता था, लेकिन आम तौर पर जब आप कई वस्तुओं पर वजन का उपयोग करते हैं तो आप 0 डीपी करना चाहते हैं क्योंकि अधिकांश समय आप चौड़ाई को wrap_content पर चौड़ाई पर विचार करने के विपरीत चौड़ाई चाहते हैं और फिर वजन का उपयोग करके शेष जगह भरें। – kabuko

+0

0 डीआईपी के विकल्प के रूप में, मैं अक्सर वजन लागू करते समय fill_parent/match_parent का उपयोग करता हूं, ऐसा लगता है। लेकिन यह ओपी के विवेकाधिकार पर निर्भर है। – MrZander

+0

मैंने भी कोशिश की है, लेकिन मुझे इसके साथ समस्याएं आई हैं। यह आमतौर पर काम करता है, लेकिन कभी-कभी (लेकिन लगातार नहीं) अजीब चीजें होती हैं जहां यह अपेक्षा से बड़ी हो सकती है। मुझे स्क्रीन से धक्का देने वाली चीज़ों में समस्याएं आई हैं। – kabuko

3

मेरे मामले में मैं लेआउट_विड्थ विशेषता को टेबललेआउट में रखना भूल गया।

यह थोड़ा TableRow वजह से भ्रमित जो है TableLayout के एक बच्चे को एक layout_width तो मैं इस मुद्दे में भाग गया की आवश्यकता नहीं है ...

+0

मुझे एक समान समस्या थी। यदि आप एक्सएमएल से अपना लेआउट बढ़ा रहे हैं और आपके पास उस एक्सएमएल की जड़ के रूप में एक टेबलरो है, तो आपको टेबलरो की चौड़ाई निर्दिष्ट करनी होगी। – Tiago

1

मुझे लगता है कि यू dp क्यों अपने कोड .क्या चौड़ाई आकार के बाद नहीं डाल दिया है शायद काम नहीं कर रहा है। पूर्व android:layout_weight="20" इस android:layout_weight="20dp"

संबंधित मुद्दे