2012-09-14 8 views
9

मैं निम्नलिखित XML लेआउट है:यह लाइनरलाइटआउट एंड्रॉइड का उपयोग करना चाहिए: layout_height = "wrap_content"?

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" > 

    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" // ==> here I get the error. 
    android:orientation="vertical" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Test" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="5dp" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="2dip" 
     android:background="#298EB5" 
     android:orientation="horizontal" /> 


    </LinearLayout> 
</ScrollView> 

लेकिन मैं बत्ती संदेश मिलता है:

यह LinearLayout एंड्रॉयड का उपयोग करना चाहिए: layout_height = "wrap_content"

मैं क्यों मिलता है ये संदेश?

उत्तर

10

LinearLayout के आधार पर लेआउट रैप की ऊंचाई की आवश्यकता है या तो दोनों तरफ या एक दूसरे के शीर्ष पर तत्वों को ढेर करने के लिए डिज़ाइन किया गया है। मेरा अनुमान है कि यह फाहा चेतावनी ScrollView

Documentation के कारण virtical स्टैकिंग की सिफारिश की गई है:

"सभी एक LinearLayout के बच्चों एक के बाद एक खड़ी दिखती हैं, तो लंबवत सूची ही पंक्ति प्रति एक बच्चे को होगा इससे कोई फर्क नहीं पड़ता कि वे कितने चौड़े हैं, और एक क्षैतिज सूची केवल एक पंक्ति ऊंची होगी (सबसे ऊंचे बच्चे की ऊंचाई, प्लस पैडिंग)। एक रैखिक लयआउट प्रत्येक के बच्चों और गुरुत्वाकर्षण (दाएं, केंद्र, या बाएं संरेखण) के बीच मार्जिन का सम्मान करता है बच्चे। "

+3

फ़ॉर्मेटिंग के लिए धन्यवाद ब्रो। –

3

अपने एक प्रकार का वृक्ष चेतावनी का उपयोग करना चाहिए

android:layout_height="wrap_content" 

wrap_content ऐड के अनुसार ऊंचाई पर है सामग्री की आवश्यकता है।

4

यह कोई त्रुटि नहीं है लेकिन यह सुझाव नहीं दिया जाता है क्योंकि यह कुछ मामलों में अवांछित परिणाम देगा। स्क्रॉलव्यू का उपयोग करते समय मैं रोमैन द्वारा article का पालन करता हूं। मुझे आशा है कि यह संदेश के कारण की व्याख्या करेगा।

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