Android 以编程方式将textView添加到LinearLayout。已添加项,但它们似乎是空的

Android 以编程方式将textView添加到LinearLayout。已添加项,但它们似乎是空的,android,android-layout,Android,Android Layout,我需要滚动查看与图像和文本视图下它 我有这样的布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffffff"> <EditText a

我需要滚动查看与图像和文本视图下它

我有这样的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffffff">

    <EditText
        android:id="@+id/comment_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/addCommentButton"
        android:inputType="text"
        android:textColor="#ff000000" />

    <Button
        android:id="@+id/addCommentButton"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/comment_text"
        android:text="Send" />

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/comment_text"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="top">

            <ImageView
                android:id="@+id/image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="description"
                android:maxHeight="300dp" />

            <LinearLayout
                android:id="@+id/comments"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#ffffffff"
                android:orientation="vertical">
            </LinearLayout>

        </LinearLayout>
    </ScrollView>

</RelativeLayout>
我得到了这个,但是
comment.getMessage()
不是空的。 我做错了什么

请看截图


试试这种方法,希望这能帮助你解决问题。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffffff"
    android:orientation="vertical"
    android:padding="5dp">

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="top"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="description"
                android:adjustViewBounds="true"
                android:maxHeight="300dp" />

            <LinearLayout
                android:id="@+id/comments"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#ffffffff"
                android:orientation="vertical">
            </LinearLayout>

        </LinearLayout>
    </ScrollView>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp">
        <EditText
            android:id="@+id/comment_text"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:textColor="#ff000000" />

        <Button
            android:id="@+id/addCommentButton"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="Send" />
    </LinearLayout>

</LinearLayout>


谢谢。它的工作,但当我添加更多的项目,以前的消失。我是说。我有10点意见。如果我添加了第11条,第一条就消失了。没有调用removeAllView()就没有任何LinearLayout项目消失在任何地方。好的。谢谢我们将进行更多调查。谢谢你的布局!您好,您能告诉我为什么要在0索引上添加新评论吗?因为我需要从底部开始的最新评论
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffffff"
    android:orientation="vertical"
    android:padding="5dp">

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="top"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="description"
                android:adjustViewBounds="true"
                android:maxHeight="300dp" />

            <LinearLayout
                android:id="@+id/comments"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#ffffffff"
                android:orientation="vertical">
            </LinearLayout>

        </LinearLayout>
    </ScrollView>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp">
        <EditText
            android:id="@+id/comment_text"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:textColor="#ff000000" />

        <Button
            android:id="@+id/addCommentButton"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="Send" />
    </LinearLayout>

</LinearLayout>