here我正在开发一个短信应用程序,我必须在我的应用程序中保存收到的短信。我使用自定义列表视图来保存短信内容,短信发件人和短信日期。当传入SMS短,即4 5行时,这完全正常。 但问题是如果SMS很长,即超过5 6行,那么listview没有显示完整的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“消息内容”文本视图,问题就在那里我想
我在活动中调用主列表视图。主列表视图的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是自定义列表视图内容的名称 请帮助!!
答案 0 :(得分: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
的值。
答案 1 :(得分:0)
尝试改变
的值 android:singleline="false"
答案 2 :(得分:0)
我已经在我身边测试了你的代码并根据你的需要做了一些改变
<?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 :(得分:0)
将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 :(得分:0)
从oftxt_messageContent和 android:singleLine="true"
中删除了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>
答案 5 :(得分:0)
只需添加此android:singleLine="false"
而不是android:singleLine="true"
它会起作用......