2013-03-18 7 views
10

के रूप में स्थापित:ऊंचाई, पूरे स्क्रीन पर आ जाएगा, हालांकि मैं एक LinearLayout अंदर इस ListView है wrap_content

<?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" > 

    <TextView 
     .../> 

    <EditText /> 
     ... 
    </EditText> 


    <ListView 
     android:id="@+id/words_list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
    </ListView> 

</LinearLayout> 

सूची प्रोग्राम के रूप में एक SimpleCursorAdapter की आबादी है:

adapter = new SimpleCursorAdapter(this, R.layout.list_row_search, mCursor, from, to); 

list_row_search एक TableLayout है दो टेबलरो के साथ:

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/TableLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <View 
     android:layout_height="1dip" 
     android:background="#FF33B5E5" /> 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/list_lesson" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:padding="1dip" 
      android:textSize="12sp" /> 

     <TextView 
      android:id="@+id/list_name" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="5.25" 
      android:padding="1dip" 
      android:paddingRight="10dp" 
      android:textSize="18sp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/list_flex" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="12.5" 
      android:padding="1dip" 
      android:paddingRight="10dp" /> 

     <TextView 
      android:id="@+id/list_rom" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="6.25" 
      android:padding="1dip" 
      android:paddingRight="10dp" /> 
    </TableRow> 

    <View 
     android:layout_height="0.1dip" 
     android:background="#404040" /> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/list_related" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:paddingRight="10dp" 
      android:textStyle="italic" /> 

     <TextView 
      android:id="@+id/list_ant" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:paddingRight="10dp" /> 

     <TextView 
      android:id="@+id/list_engl" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:paddingRight="10dp" /> 
    </TableRow> 

    <View 
     android:layout_height="1dip" 
     android:background="#FF33B5E5" /> 

</TableLayout> 

अब जब सूची पॉप्युलेट हो जाती है, तो एल istView छेद स्क्रीन पर कब्जा करता है, भले ही डेटाबेस में केवल एक तत्व पाया गया हो। ग्रहण में पदानुक्रम दृश्य बहुत स्पष्ट दिखाता है कि सूची दृश्य वह है जो स्क्रीन को भरता है।

क्या आप बता सकते हैं, समस्या कहां है? आपके समय के लिए धन्यवाद!

उत्तर

14

आपको ListView की ऊंचाई के लिए wrap_content का उपयोग नहीं करना चाहिए। wrap_content का अर्थ है "मुझे अपने सभी बच्चों को पकड़ने के लिए जितना बड़ा हो उतना बड़ा बनाओ।" जब आप मानते हैं कि आपका डेटा सेट संभावित रूप से बहुत बड़ा हो सकता है, तो यह एक बहुत बुरा विचार की तरह लगना चाहिए। चूंकि आप लाइनरलाइट का उपयोग कर रहे हैं, तो अपनी सूची दृश्य layout_height="0dp" और layout_weight="1" दें।

ListView स्क्रीन के शेष को ले जाने के लिए ठीक है। यदि इसमें केवल एक पंक्ति है, तो यह एक पंक्ति दिखाएगी, कोई बड़ा सौदा नहीं होगा। जब तक आप सूची के नीचे कुछ दिखाने की कोशिश नहीं कर रहे हैं, लेकिन जो मैंने आपको ऊपर बताया है उसे पूरा करना चाहिए।

+1

आपके उत्तर के लिए धन्यवाद, लेकिन "wrap_content" से ऊंचाई को 0dp/weight = 1 में बदलकर एक ही व्यवहार में परिणाम: ListView पूरी स्क्रीन भरता है। असल में मैं सूची के नीचे कुछ दिखाने की कोशिश कर रहा था, लेकिन एक संपूर्ण सूची दृश्य केवल एक तत्व दिखा रहा था (जब केवल एक पाया गया) मुझे नीचे दी गई सूची डाल दिया ... –

+0

आप अभी भी इसे ऊंचाई = 0 और वजन = 1 दे सकते हैं। इसके बाद एक और दृश्य जोड़ें और LinearLayout उस आइटम के लिए स्थान आवंटित करेगा और शेष को सूची दृश्य में देगा। यदि इसके बजाय आप सूची के निचले हिस्से में तय की गई वस्तु रखने की कोशिश कर रहे हैं लेकिन सूची की सामग्री के साथ स्क्रॉल करते हैं, तो आप 'ListView.addFooterView() ' – Karakuri

0

यदि ऊपर काम नहीं करता है, तो आप रैखिक के बजाय RelativeLayout का उपयोग कर सकते हैं और EditText के नीचे ListView डाल सकते हैं।

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