我有TextViews,我想有自己的行与换行符。 TextViews与部分功能的对象。我想显示其在线路中断的序列。

这是我的代码:

int i;
String p = "one, two, three, four, five, six, seven, eight, ten";
String[] array = p.split(",");

LinearLayout groupLL = new LinearLayout(this);
LinearLayout.LayoutParams gLLP = new LinearLayout.LayoutParams(
    new ViewGroup.MarginLayoutParams(
    LinearLayout.LayoutParams.WRAP_CONTENT,
    LinearLayout.LayoutParams.WRAP_CONTENT));

LinearLayout.LayoutParams mlp = new LinearLayout.LayoutParams(
    new ViewGroup.MarginLayoutParams(
    LinearLayout.LayoutParams.FILL_PARENT,
    LinearLayout.LayoutParams.WRAP_CONTENT));
mlp.setMargins(0, 0, 10, 0);

for (i = 0; i < array.length; i++) {
    TextView newTextView = new TextView(this);
    newTextView.setText(array[i]);
    newTextView.setBackgroundColor(Color.RED);
    newTextView.setSingleLine(true);
    newTextView.setTextSize(20);

    groupLL.addView(newTextView, mlp);
}

ll.addView(groupLL, gLLP);


这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ScrollView02"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

    <RelativeLayout
    android:id="@+id/RelativeLayout02"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout android:id="@+id/LinearLayout2"
              xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical" >
    </LinearLayout>

    </RelativeLayout>

</ScrollView>


我有这个:

|one two three four five s|
|                         |
|                         |


我要这个:

|one two three four five  |
|six seven eight ten      |
|                         |




编辑:

如果我改变
newTextView.setSingleLine(真);

newTextView.setSingleLine(假);
然后,我有这样的:

|one two three four five six |
|                         sev|
|                          en|

最佳答案

更改

newTextView.setSingleLine(true);




 newTextView.setSingleLine(false);


希望能对我的朋友有用...

10-07 19:26