Android ListView带有多行文本视图空间行
list_layout.xml:Android ListView带有多行文本视图空间行,android,xml,android-layout,listview,textview,Android,Xml,Android Layout,Listview,Textview,list_layout.xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginLeft="6dp" android:layout_marginRight="6dp"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
>
<TextView
android:id="@+id/txtAdi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColor="@color/DarkGreen"
/>
我在textview中添加了android:maxLines=“2”和android:ellipsize=“end”,然后如下所示:
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:listSelector="@drawable/listselector" >
</ListView>
sample text 1
-------------------
sample multiline
text 2
--------------------
sample text 3
--------------------
sample text 1
-------------------
sample multiline
text 2...
--------------------
sample text 3
--------------------
示例文本1
-------------------
样本多行
文本2。。。
--------------------
示例文本3
--------------------
所以我想显示最多两行,如果超过两行的文本附加了三个点。
这是可能的解决方案。您能粘贴列表适配器代码吗?我添加了列表适配器代码确保您的文本数据结尾不包含新行('\n')符号。没有新行符号我复制了您的代码,这给了我一个很好的结果。我想你应该考虑一下你的光标,它可能会在结尾或其他地方设置一条新的线,试着打印出这些多行项目,看看它的末尾是否有什么东西。
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
getApplicationContext(), R.layout.list_layout, c, from, to, 10);
ListView list = (ListView) findViewById(R.id.listView1);
list.setAdapter(adapter);
<TextView
android:id="@+id/txtAdi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColor="@color/DarkGreen"
android:maxLines="2"
android:ellipsize="end"
/>
sample text 1
-------------------
sample multiline
text 2...
--------------------
sample text 3
--------------------