के अंदर रिलेवेटिवआउट में दृश्यों को गतिशील रूप से जोड़ना मैं गतिशील रूप से कई रिलेवेटलाइट्स को एक लाइनरलायआउट में जोड़ने की कोशिश कर रहा हूं जो एक रिलेवेटलाइट के अंदर है, जो स्क्रॉलव्यू के अंदर है। जब सभी दृश्यों की कुल ऊंचाई फोन स्क्रीन के आकार से अधिक हो जाती है, तो सभी विचार सही तरीके से प्रदर्शित होते हैं। लेकिन जब गतिशील रूप से जोड़े गए दृश्यों का कुल आकार स्क्रीन भरने के लिए पर्याप्त नहीं है, तो केवल पहला सापेक्ष लेआउट तत्व दिखाया गया है और अन्य स्क्रीन में प्रदर्शित नहीं होते हैं। मैं वास्तव में निराश हूं और समझ में नहीं आता क्यों।स्क्रॉलव्यू
यहाँ कोड को गतिशील रेखीय लेआउट के अंदर विचारों को भरने के लिए है:
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 फ़ाइल है
और स्क्रीनशॉट:
पर्याप्त लेआउट के बिना: (सही, स्क्रीन भर जाता है)
मैं:
पर्याप्त लेआउट के साथ(गलत, 3 टिप्पणियां दिखाने के लिए की जरूरत है) पहले मामले में सभी तीन टिप्पणियों को दिखाने की जरूरत है:/अग्रिम धन्यवाद।
हेडर और फ़ूटर के साथ ListView का उपयोग क्यों नहीं करें? –
वास्तव में मेरे पास उन लोगों के ऊपर कई अन्य विचार हैं जो एक सूची की तरह दिखते हैं: कई छविदृश्य, बटन इत्यादि। इसलिए यह एक आम मामला नहीं है लेकिन मुझे इस स्थिति को हल करने की भी आवश्यकता है, क्योंकि मैं इस तथ्य पर भरोसा नहीं कर सकता कि हर कोई इस गतिविधि में अन्य दृश्य शुरू किया जाएगा। कोई विचार? – ecem