Я пытаюсь добавить несколько динамически созданных RelativeLayouts в LinearLayout, который находится внутри RelativeLayout, который находится внутри ScrollView. Когда общая высота всех представлений превышает размер экрана телефона, все представления отображаются правильно. Но когда общего размера динамически добавляемых представлений недостаточно для заполнения экрана, отображается только первый элемент RelativeLayout, а остальные не отображаются на экране. Я действительно безнадежен и не понимаю, почему.
Вот код для динамического заполнения представлений внутри линейного макета:
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: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-файл для этого действия:
<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>
И скриншоты:
Без достаточного количества макетов : (НЕВЕРНО, нужно показать 3 комментария)
При достаточном количестве раскладок: (ПРАВИЛЬНО ОДИН, экран заполнен)
Мне просто нужно показать все три комментария в первом случае :/ Спасибо в продвигать.