我有一个应用程序,点击后会显示带有新闻内容的活动。我想在底部显示评论,这些评论是在异步任务中动态加载的。
一种方法是使用 ListView 和自定义 ArrayAdapter,但是,我必须将 ListView 放在 ScrollView 中,这是一个问题,即使我手动覆盖 ListView 的高度。它显示一个列表项,以及下一个列表项的一部分。
另一种方法是将LinearLayout定义为评论的持有者,而不是膨胀在它自己的xml文件中定义的另一个LinearLayouts,填充它的内容,附加到持有者的视图。从程序的角度来看,它工作正常,除了它将评论推送到新闻内容下方。就像,它在内容 od news 下创建了另一个可滚动的评论视图(内容与其重叠)。
有没有其他与列表无关的方法,或者我怎样才能使其他方法起作用。
包含新闻内容的 xml 布局的相关代码片段是:
<LinearLayout> //global layout
<LinearLayout>
//views that hold title, date, content
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/commentsHolder"
android:orientation="vertical">
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#ed1b24"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="KOMENTARI"
android:layout_marginLeft="5dp"/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#ed1b24"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:orientation="vertical"
android:id="@+id/comments_holder_view"
android:layout_weight="1">
</LinearLayout>
</LinearLayout>
</LinearLayout>
对应于一条评论的代码是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/comments_holder_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/comment_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/comments_back_details"
android:text="Ovde ide tekst komentara, koji se, naravno, dinamicki dodaje."/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/comment_author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/categoryStyle"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" | "
style="@style/categoryStyle"
/>
<TextView
android:id="@+id/comment_pubdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/categoryStyle"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:orientation="horizontal"
android:layout_margin="5dp"
android:background="#d1d1d1">
</LinearLayout>
非常感谢您的回复。这对我来说相当重要。