2011-02-24 31 views
6

मुझे LinearLayout से addView विधि के साथ समस्याएं आ रही हैं। मुझे नहीं पता क्यों, लेकिन अगर मैं तीन विचार जोड़ता हूं तो केवल पहला प्रदर्शित होता है। यहाँ कोड है:LinearLayout addView ठीक से काम नहीं करता

Comment[] comments = posts[position].getComments(); 
LinearLayout layout = (LinearLayout)convertView.findViewById(R.id.post_list_item_comments); 
layout.removeAllViews(); 
for(int i=0; i<comments.length; i++) { 
    View comment = inflater.inflate(R.layout.post_list_item_comment,null); 
    ((TextView)comment.findViewById(R.id.post_list_item_comment_name)).setText(comments[i].getFrom().getName()); 
    ((TextView)comment.findViewById(R.id.post_list_item_comment_message)).setText(comments[i].getText()); 
    layout.addView(comment,i); 
} 

मैं addView (टिप्पणी) भी साथ की कोशिश की है, लेकिन एक ही परिणाम के साथ।

यह दृश्य का कोड है जिसे मैं findViewById mehthod का उपयोग करने के लिए पुनर्प्राप्त करता हूं।

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <View 
     android:id="@+id/post_list_item_comment_divider" 
     android:layout_width="fill_parent" 
     android:layout_height="1dip" 
     android:background="@drawable/divider" 
     android:layout_marginTop="2dip" 
     android:layout_marginBottom="2dip"/> 
    <ImageView 
     android:id="@+id/post_list_item_comment_photo" 
     android:layout_width="40dip" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/post_list_item_comment_divider" 
     android:adjustViewBounds="true"/> 
    <TextView 
     android:id="@+id/post_list_item_comment_name" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_toRightOf="@id/post_list_item_comment_photo" 
     android:layout_below="@id/post_list_item_comment_divider" 
     android:maxLines="2" 
     android:ellipsize="end"/> 
    <TextView 
     android:id="@+id/post_list_item_comment_message" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_toRightOf="@id/post_list_item_comment_photo" 
     android:layout_below="@id/post_list_item_comment_name" 
     android:textSize="13sp" 
     android:maxLines="2" 
     android:ellipsize="end"/> 
</RelativeLayout> 

उत्तर

20

आप LinearLayout उन्मुखीकरण घोषित नहीं है ... डिफ़ॉल्ट रूप से क्षैतिज है, अभिविन्यास कार्यक्षेत्र

<LinearLayout 
    android:id="@+id/post_list_item_comments" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:paddingLeft="40dip" 
    android:layout_below="@id/post_list_item_footer_text" 
    android:visibility="gone"/> 
+0

धन्यवाद स्थापित करने की कोशिश करो! तुम कठोर हो मुझे नहीं पता कि मुझे क्यों लगता है कि डिफ़ॉल्ट लंबवत है। – Adrian

+0

धन्यवाद लड़का ^।^आपका उत्तर इतना उपयोगी है। – anticafe

+0

आपको बहुत फ्रैंको धन्यवाद –

2

अगर वहाँ वास्तव में केवल 1 दृश्य जोड़ा गया है की जाँच करने के पदानुक्रम दर्शक प्रयोग करें, या कि आप केवल एक दृश्य देख सकते हैं:

<LinearLayout 
    android:id="@+id/post_list_item_comments" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:paddingLeft="40dip" 
    android:layout_below="@id/post_list_item_footer_text" 
    android:visibility="gone"/> 

और यह एक्सएमएल कि मैं बढ़ रहा है। उदाहरण के लिए, यदि आप इसे दोहराते हैं तो यह लाइन android:layout_below="@id/post_list_item_footer_text" परेशानी हो सकती है? मुझे लगता है कि के लिए अपेक्षित व्यवहार नहीं पता ...

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