我有一个应用程序,点击一些后,会显示新闻内容的活动。我想在其底部显示注释,这些注释是在异步任务中动态加载的。
一种方法是使用 ListView 和自定义 ArrayAdapter,但是,我必须将 ListView 放入 ScrollView 中,即使我手动覆盖 ListView 的高度,这也是一个问题。它显示一个列表项以及下一项的一部分。
另一种方法是将 LinearLayout 定义为注释持有者,而不是膨胀在其自己的 xml 文件中定义的另一个 LinearLayout,填充其内容,附加到持有者的视图。从程序的角度来看,它工作得很好,除了它将评论推送到新闻内容下方。就像,它在新闻内容下方创建了另一个可滚动的评论视图(内容与其重叠)。
有没有其他与列表无关的方法来做到这一点,或者我怎样才能使其他方法发挥作用。
保存新闻内容的 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>
非常感谢您的回复。这对我来说非常重要。
我不太确定你是如何充气的comments
,但我会这样做。
声明评论Layout
as a LinearLayout
并给它一个 id,然后获取对此的引用LinearLayout
:
LinearLayout commentsLayout=(LinearLayout)findViewById(R.id.commentsLayoutId);
然后添加孩子Views
到这个布局:
commentsLayout.addView(newComment);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)