列表视图不显示完整文本

List view not showing complete Text

我正在开发一个 SMS 应用程序,我必须在我的应用程序中保存收到的 SMS。我使用自定义列表视图来保存短信内容、短信发件人和短信日期。当传入的 SMS 很短时,即 4 5 行,这完全可以正常工作。 但问题是,如果 SMS 很长,即超过 5 6 行,则列表视图不会显示完整的 SMS。它显示前 4 5 行,但剪切了 SMS 的下一部分。我不知道该怎么办,完全卡住了。

这是我的自定义列表视图内容

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<ImageView
    android:id="@+id/product_icon"
    android:layout_width="40dp"
    android:layout_height="50dp"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="2dp"
    android:padding="3dp"
    android:src="@drawable/personn"
    />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center|center_vertical"
    android:orientation="vertical"
    android:paddingLeft="2dp"

    >

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center|center_vertical"
    android:orientation="horizontal"
    android:paddingLeft="0dp"

    >
    <TextView
        android:id="@+id/txt_msgTO"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="2dp"
        android:layout_marginTop="15dp"
        android:lineSpacingExtra="3dp"
        android:textSize="16sp"
        android:text="Ahtesham"
        android:textStyle="bold"
        android:textColor="#070B19"
        android:minLines="1"
        android:layout_marginRight="5dp"
        android:gravity="center_vertical"
        />

     <TextView
        android:id="@+id/date"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:lineSpacingExtra="3dp"
        android:textSize="10sp"
        android:text="Ahtesham"
        android:textStyle="bold"
        android:gravity="right"
        android:layout_marginRight="5dp"
        android:textColor="#070B19"

        />
    </LinearLayout>

    <TextView
        android:id="@+id/txt_messageContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="2dp"
        android:lineSpacingExtra="3dp"
        android:textColor="#585858"
        android:textSize="13sp"
        android:singleLine="true"

        android:text="Heloo How are you"
        android:layout_marginTop="0dp"
        android:layout_marginRight="5dp"
        android:gravity="center_vertical"
        />


</LinearLayout>

<TextView
    android:id="@+id/empty"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />

请查看id "message content"文本视图,我认为问题就在那里

我正在调用 activity 中的主列表视图。 xml 主列表视图的代码是

<ListView
    android:id="@+id/messageList"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginLeft="4dp"
    android:layout_marginRight="4dp"
    android:cacheColorHint="@null"

    android:listSelector="@android:color/transparent"
    android:layout_marginBottom="45dp" />

最后,我在此列表视图中获取收件箱消息

public void populateMessageList() {
fetchInboxMessages();

messageListAdapter = new SmsList(this,R.layout.smscontent, recordsStored);
messageList.setAdapter(messageListAdapter);

}

smscontent 是自定义列表视图内容的名称 请帮忙!!

尝试更改

的值
 android:singleline="false"

Text View 中为 txt_messageContent 使用此属性。

android:maxLines="10"
android:lines="10"
android:singleLine="false" 

编辑 1:

改变这个。

android:layout_height="wrap_content"

编辑 2:

添加这个。

android:inputType="textMultiLine"

编辑 3:

更改了 Layout 应用这个。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/product_icon"
        android:layout_width="40dp"
        android:layout_height="50dp"
        android:layout_marginLeft="2dp"
        android:layout_marginTop="10dp"
        android:padding="3dp"
        android:src="@drawable/ic_add_black" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center|center_vertical"
        android:orientation="vertical"
        android:paddingLeft="2dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center|center_vertical"
            android:orientation="horizontal"
            android:paddingLeft="0dp">

            <TextView
                android:id="@+id/txt_msgTO"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="15dp"
                android:gravity="center_vertical"
                android:lineSpacingExtra="3dp"
                android:minLines="1"
                android:text="Ahtesham"
                android:textColor="#070B19"
                android:textSize="16sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/date"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dp"
                android:layout_marginTop="15dp"
                android:gravity="right"
                android:lineSpacingExtra="3dp"
                android:text="Ahtesham"
                android:textColor="#070B19"
                android:textSize="10sp"
                android:textStyle="bold" />
        </LinearLayout>

        <TextView
            android:id="@+id/txt_messageContent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="0dp"
            android:gravity="center_vertical"
            android:lineSpacingExtra="3dp"
            android:singleLine="false"
            android:text="Heloo How are you,Heloo How are you,Heloo How are you,Heloo How are you,Heloo How are you,Heloo How are youHeloo How are you,Heloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are you,Heloo How are you,Heloo How are you,Heloo How are you,Heloo How are you,Heloo How are youHeloo How are you,Heloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are you,Heloo How are you,Heloo How are you,Heloo How are you,Heloo How are you,Heloo How are youHeloo How are you,Heloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are you,Heloo How are you,Heloo How are you,Heloo How are you,Heloo How are you,Heloo How are youHeloo How are you,Heloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are you,Heloo How are you,Heloo How are you,Heloo How are you,Heloo How are you,Heloo How are youHeloo How are you,Heloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are youHeloo How are you"
            android:textColor="#585858"
            android:textSize="13sp" />


    </LinearLayout>
</LinearLayout>

注意:您可以根据需要更改 maxLines and lines 的值。

我已经在我这边测试了你的代码,并根据你的需要做了一些修改

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/product_icon"
        android:layout_width="40dp"
        android:layout_height="50dp"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="2dp"
        android:padding="3dp"

        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center|center_vertical"
        android:orientation="vertical"
        android:paddingLeft="2dp"

        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center|center_vertical"
            android:orientation="horizontal"
            android:paddingLeft="0dp"

            >
            <TextView
                android:id="@+id/txt_msgTO"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="2dp"
                android:layout_marginTop="15dp"
                android:lineSpacingExtra="3dp"
                android:textSize="16sp"
                android:text="Ahtesham"
                android:textStyle="bold"
                android:textColor="#070B19"
                android:minLines="1"
                android:layout_marginRight="5dp"
                android:gravity="center_vertical"
                />

            <TextView
                android:id="@+id/date"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:lineSpacingExtra="3dp"
                android:textSize="10sp"
                android:text="Ahtesham"
                android:textStyle="bold"
                android:gravity="right"
                android:layout_marginRight="5dp"
                android:textColor="#070B19"

                />
        </LinearLayout>

        <TextView
            android:id="@+id/txt_messageContent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:lineSpacingExtra="3dp"
            android:textColor="#585858"
            android:textSize="13sp"


            android:text="Heloo How are you I/ServiceManager: Waiting for service AtCmdFwd...
05-05 04:53:57.217 32404-32404/? I/ServiceManager: Waiting for service AtCmdFwd...
05-05 04:53:58.217 32404-32404/? I/ServiceManager: Waiting for service AtCmdFwd...I/ServiceManager: Waiting for service AtCmdFwd...
05-05 04:53:57.217 32404-32404/? I/ServiceManager: Waiting for service AtCmdFwd...
05-05 04:53:58.217 32404-32404/? I/ServiceManager: Waiting for service AtCmdFwd..."
            android:layout_marginTop="0dp"
            android:layout_marginRight="5dp"
            android:gravity="center_vertical"
            />


    </LinearLayout>
    </LinearLayout>

这是这个的截图..

将您的 TextView 身高更改为 wrap_content 并删除 android:singleline="true"

<TextView
        android:id="@+id/txt_messageContent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="2dp"
        android:lineSpacingExtra="3dp"
        android:textColor="#585858"
        android:textSize="13sp"
        android:text="Heloo How are you"
        android:layout_marginTop="0dp"
        android:layout_marginRight="5dp"
        android:gravity="center_vertical"
        />

删除了 android:singleLine="true" fromtxt_messageContent 和 txt_messageContent 并且它正在工作:-

    <TextView
        android:id="@+id/txt_messageContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="2dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="0dp"
        android:gravity="center_vertical"
        android:lineSpacingExtra="3dp"
        android:singleLine="true"
        android:text="as \n as \n  asas\n as \n  asas\n as sas \n sasc \n as \n ass \n as \n aad \n as \n  add\n as \n add \n as \n"
        android:textColor="#585858"
        android:textSize="13sp" />
</LinearLayout>

只需添加这个 android:singleLine="false" 而不是 android:singleLine="true" 它会起作用...