私はクリックした後にニュースコンテンツのアクティビティを表示するアプリを持っています。私はコメントの一番下に、非同期タスクに動的にロードされるコメントを表示します。(線形)レイアウト内にビューをプログラムで追加する(ScrollViewの中にあります)
1つのアプローチはListViewとカスタムArrayAdapterを使用することですが、リストビューの高さを手動でオーバーライドしても、リストビューをScrollView内に置く必要があります。 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>
は、いずれかのためにありがとうございました応答。これは私にとっては非常に重要です。
通常、 – njzk2
あなたはOvidiuを投稿したのとまったく同じでしたが、うまくいきましたが、どういうわけか、その線形レイアウト(idがcomments_holder_vieの場合)を使用して、あなたは 'getLayoutInflater() w)は他のレイアウトの下に横たわっている。静的に(手動で)複数のコメントレイアウトを含めると、すべてがうまく表示されます。これらのビューを動的に追加すると問題が発生するようです。しかし、返答のためには余裕がある。 – Dimmy3
追加されたビュー(コメント)の作成方法のコードを投稿してください。 –