8

के अंदर रिलेवेटिवआउट में दृश्यों को गतिशील रूप से जोड़ना मैं गतिशील रूप से कई रिलेवेटलाइट्स को एक लाइनरलायआउट में जोड़ने की कोशिश कर रहा हूं जो एक रिलेवेटलाइट के अंदर है, जो स्क्रॉलव्यू के अंदर है। जब सभी दृश्यों की कुल ऊंचाई फोन स्क्रीन के आकार से अधिक हो जाती है, तो सभी विचार सही तरीके से प्रदर्शित होते हैं। लेकिन जब गतिशील रूप से जोड़े गए दृश्यों का कुल आकार स्क्रीन भरने के लिए पर्याप्त नहीं है, तो केवल पहला सापेक्ष लेआउट तत्व दिखाया गया है और अन्य स्क्रीन में प्रदर्शित नहीं होते हैं। मैं वास्तव में निराश हूं और समझ में नहीं आता क्यों।स्क्रॉलव्यू

यहाँ कोड को गतिशील रेखीय लेआउट के अंदर विचारों को भरने के लिए है:

LinearLayout commentsLayout = (LinearLayout) findViewById(R.id.comments_layout); 

LayoutInflater inflater = (LayoutInflater) 
    this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

for(Comment c: commentsList) { 

    RelativeLayout layoutItem = (RelativeLayout) inflater.inflate(
     R.layout.list_item_comment, null, false); 

     TextView tv = (TextView) layoutItem.findViewById(R.id.textView); 
     ImageView iv = (ImageView) layoutItem.findViewById(R.id.imageView); 

     // set tv's text 
     // set iv's image and onclicklistener, nothing fancy here, everything goes well 

     commentsLayout.addView(layoutItem); 
} 
यहाँ

list_item_comment.xml है:

<RelativeLayout 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:id="@+id/main_layout" 
> 
... 

    <ScrollView 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" 
    android:id="@+id/scrollView" 
    > 

     <RelativeLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/relativeContainer" 
     > 

     ... 

      <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/comments_layout" 
      /> 

     </RelativeLayout> 

    </ScrollView> 

</RelativeLayout> 
:

<RelativeLayout 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@color/white" 
> 
    <ImageView 
    android:id="@+id/imageView" 
    android:layout_width="50dip" 
    android:layout_height="50dip" 
    android:layout_alignParentLeft="true" 
    android:layout_marginTop="10dp" 
    android:layout_marginLeft="10dp" 
    /> 

    <TextView 
    android:id="@+id/textView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_margin="10dp" 
    android:textSize="16sp" 
    android:layout_toRightOf="@id/imageView" 
    /> 
</RelativeLayout> 

और यहाँ इस गतिविधि के लिए xml फ़ाइल है

और स्क्रीनशॉट:

पर्याप्त लेआउट के बिना: (सही, स्क्रीन भर जाता है)

correct one

मैं:

Incorrect one

पर्याप्त लेआउट के साथ

(गलत, 3 टिप्पणियां दिखाने के लिए की जरूरत है) पहले मामले में सभी तीन टिप्पणियों को दिखाने की जरूरत है:/अग्रिम धन्यवाद।

+0

हेडर और फ़ूटर के साथ ListView का उपयोग क्यों नहीं करें? –

+0

वास्तव में मेरे पास उन लोगों के ऊपर कई अन्य विचार हैं जो एक सूची की तरह दिखते हैं: कई छविदृश्य, बटन इत्यादि। इसलिए यह एक आम मामला नहीं है लेकिन मुझे इस स्थिति को हल करने की भी आवश्यकता है, क्योंकि मैं इस तथ्य पर भरोसा नहीं कर सकता कि हर कोई इस गतिविधि में अन्य दृश्य शुरू किया जाएगा। कोई विचार? – ecem

उत्तर

0

बजाय fill_parent, अपने list_item_comment.xmlwrap_content के <RelativeLayout> की layout_height बदलने का प्रयास करें।

इसके अलावा, आपको अपनी गतिविधि के xml के <ScrollView> के अंदर अन्य <RelativeLayout> क्यों चाहिए। LinearLayout वह करने के लिए पर्याप्त है जो आप अपनी गतिविधि को दिखाना चाहते हैं। शायद आप इसे हटा सकते हैं।

+0

मैंने आपके सुझाव की कोशिश की लेकिन यह समस्या को हल नहीं कर रहा है:/असल में यह मेरी गतिविधि का एक आम मामला नहीं है, आम तौर पर एक 2 छविदृश्य, एक बटन, कई टेक्स्टव्यू इत्यादि होना चाहिए इसलिए relativelayout मेरी नौकरी को आसान बनाता है। लेकिन यह एक मामला भी है (हालांकि यह दुर्लभ है), इसलिए मुझे एक समाधान मिलना चाहिए:/ – ecem

+0

@ ईसीएम, क्या आप इसके लिए समाधान ढूंढ पाएंगे? – WindsurferOak

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