【问题标题】:List view not showing complete Text列表视图未显示完整的文本
【发布时间】:2016-05-05 08:41:35
【问题描述】:

我正在开发一个短信应用程序,我必须在我的应用程序中保存收到的短信。我使用自定义列表视图来保存 SMS 内容、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" 文本视图,我认为问题可能就在那里

我在活动中调用那个主列表视图。主列表视图的 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 是自定义列表视图内容的名称 请帮忙!!

【问题讨论】:

  • 可以分享截图吗
  • 其中Text Viewtxt_messageContent?
  • @PhanVănLinh 屏幕截图添加先生
  • @jaydroider 是的,这就是文本视图
  • @ArslanAli 你知道你的消息的最大字符长度吗?

标签: android listview textview android-custom-view


【解决方案1】:

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 的值。

【讨论】:

  • 如果您有更多内容,请尝试更改值,比如说将其从 10 更改为 50 并检查。
  • 没有现在还在工作,完全被这个奇怪的问题所困扰
  • @ArslanAli 将高度更改为wrapcontent 并尝试。
  • @ArslanAli 删除 android:gravity="center_vertical" 并检查。而是给这个android:gravity="left"
  • 它终于奏效了 你真是个天才 谢谢你的时间 :)
【解决方案2】:

我已经测试了您的代码并根据您的需要进行了一些更改

<?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>

这是这个的截图..

【讨论】:

  • 但是当收到新短信时它不起作用,我用预定义的文本检查它并且它有效但是当收到短信并保存到数据库时,这个文本视图没有完全显示
【解决方案3】:

将您的 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"
        />

【讨论】:

    【解决方案4】:

    尝试通过改变

    的值
     android:singleline="false"
    

    【讨论】:

      【解决方案5】:

      从txt_messageContent 和txt_messageContent 中删除了android:singleLine="true",它正在工作:-

          <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>
      

      【讨论】:

        【解决方案6】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-10-21
          • 1970-01-01
          • 1970-01-01
          • 2015-07-01
          相关资源
          最近更新 更多