我使用支持库中的GridLayout。一些单元格包含播放器信息 - 我使用带有两个TextView的线性布局。我一直无法获取名称(第二个文本视图)进行换行。强制android的TextView包装
当前的行为:
123
John Cochtousczyon
期望的行为:
123
John
Cochtousczyon
这里的单元布局XML的当前状态:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/player_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="test" />
<TextView
android:id="@+id/player_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:minLines="2"
android:scrollHorizontally="false"
android:text="testing thisout with extra sauce"
android:textSize="18sp" />
</LinearLayout>
和代码,增加了他的网格:
lp = (GridLayout.LayoutParams) playerCell.getLayoutParams();
lp.columnSpec = GridLayout.spec(nameCol);
lp.rowSpec = GridLayout.spec(nameRow);
playerGrid.addView(playerCell, lp);
理想情况下,我想为包装名称后的最宽单元格设置列宽。我已经使用maxEms接近期望的结果,但是这需要平衡最可能需要的限制与较长名称容忍多少截断。
P'r'aps没有什么可以修改宽度 - 只是想我会问,如果所有比我更聪明的人都能解决这个问题。
感谢您的建议......在这种情况下,我有一个预先构建的字符串,所以我没有机会插入CRLF – ssdscott