クリックすると、ニュース コンテンツのアクティビティが表示されるアプリがあります。その一番下に、非同期タスクに動的にロードされるコメントを表示したいと思います。
1 つの方法は、ListView とカスタム ArrayAdapter を使用することですが、ListView を ScrollView 内に配置する必要があり、ListView の高さを手動でオーバーライドしても問題です。1 つのリスト項目と、次の項目の一部を示しています。
もう 1 つの方法は、LinearLayout をコメントのホルダーとして定義し、独自の xml ファイルで定義された別の LinearLayouts を膨張させ、その内容を入力し、ホルダーのビューに添付することです。ニュースの内容の下にコメントをプッシュすることを除いて、プログラムの観点からは問題なく動作します。ニュースのコンテンツの下に別のスクロール可能なコメント ビューを作成するようなものです (コンテンツが重なっています)。
リストとは関係のないこれを行う他の方法はありますか、または他のアプローチを機能させるにはどうすればよいですか。
ニュース コンテンツを保持する 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>
1 つのコメントに対応するコードは次のとおりです。
<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>
返信ありがとうございます。これは私にとって非常に重要です。