Android TextView不在ListView中执行换行(多行文本)

Dan*_*her 2 android listview multiline textview expandablelistview

我创建了一个3级的ExpandableListView,并且如果内容太长,则会遇到第二级和第三级使用的TextView不支持换行的问题.如果需要,它应该动态地超过一行.第一级TextView做得很好(自动),我实际上在xml中对所有三个TextView都有相同的设置.接下来是布局xmls,一个带有id groupname的TextView用于第二级(例如下图中的第一个红色X),带有id子名的一个用于第三级(例如,第二级和第三级红色X)图片如下).它应该都像在图片中的绿色钩子.

"singleLine = false"似乎不起作用.还尝试了在其他SO帖子中找到的一些不同的选项,但我所测试的并没有为我工作.像ellipsize一样,滚动horizo​​ntale,不同layout_width等等.唯一有效的是在x 100 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" />
Run Code Online (Sandbox Code Playgroud)

Ama*_*yan 5

在xml中添加此行

android:inputType="textMultiLine"
Run Code Online (Sandbox Code Playgroud)

要么

使用这样的编码添加文本,您可以使用'\n'添加换行符(但是在这里您必须手动添加断点到您想要的位置)

TextView txt1 = (TextView) findViewById(R.id.childname);
txt1.setText("Hi \nHello \nHow are You");
Run Code Online (Sandbox Code Playgroud)

结果将是


你好,你好吗

编辑接受的答案 - 删除行'android:layout_alignParentLeft ="true"