我已经创建了一个三级ExpandableListView,如果内容太长,用于第二级和第三级的TextViews不支持换行符。如果需要,它应该动态地跨越多行。第一级TextView (自动)做得很好,实际上我在xml中对所有三个TextViews都有相同的设置。紧随其后的是布局TextView,一个带有id groupname的xmls是用于第二级的(例如,下图中的第一个红色X),而一个带有id TextView with的xmls是用于第三级的(例如,下图中的第二个和第三个红色X)。这一切都应该像图片中的绿色钩子一样。
"singleLine=false“似乎不起作用。我也尝试了在其他SO帖子中找到的一些不同的选项,但我所测试的对我来说并不起作用。如椭圆大小,滚动水平故事,不同的layout_width等。唯一有效的方法是在x个dp上设置一个固定的layout_width,但这不是动态的,我说的对吗?
如果有人能帮我的话就太好了。非常感谢!
这是一个截图:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:id="@+id/childname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="60dp"
android:layout_marginLeft="60dp"
android:textColor="#AAAAAA"
android:singleLine="false"
android:text=""
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/groupname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="45dp"
android:layout_marginRight="60dp"
android:textColor="#555555"
android:singleLine="false"
android:gravity="center_vertical"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
发布于 2013-02-14 11:08:46
在xml中添加下面这一行
android:inputType="textMultiLine"或
使用如下代码添加文本,您可以使用‘\n’添加换行符(但在这里您必须手动在您想要的位置添加换行符)
TextView txt1 = (TextView) findViewById(R.id.childname);
txt1.setText("Hi \nHello \nHow are You");结果将是
Hi
问候
How are (你好吗?)
编辑接受的答案-删除行'android:layout_alignParentLeft="true“
发布于 2013-02-14 12:33:28
尝试使用LinearLayout而不是RelativeLayout作为TextView的父级
发布于 2013-06-25 17:25:34
我在ListView中将此属性添加到我的TextView中,并使其正确换行。
android:maxWidth="xxxdp"仅供参考。
https://stackoverflow.com/questions/14867013
复制相似问题