51

次のように、行を含む TableLayout を表示しています。

<?xml version="1.0" encoding="utf-8"?>
<TableRow
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

        <TextView   
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/one"
            android:layout_marginLeft="10dip"
            android:textColor="#B0171F" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/one"
            android:id="@+id/two"
            android:layout_marginLeft="10dip"
            android:ellipsize="none"
            android:singleLine="false"
            android:scrollHorizontally="false"
            android:maxLines="10"
            android:textColor="@android:color/black" />

  </RelativeLayout>

</TableRow>

私はここで見つけることができ、テキストを複数の行に折り返すことができると考えることができるすべてのものでこれを打っていますが、役に立ちません: テキストは常に 1 行に強制され、画面からはみ出します。ここで TableRow 内で作業していることは重要かもしれませんが、私が知る限り、これはこのサイトでは扱われていません。

では、2 番目の TextView を多くの行に折り返すにはどうすればよいでしょうか?

4

5 に答える 5

99

TextViewが含まれる列が縮小するように設定されている場合、TextViewはテキストを折り返します。正確に折り返されない場合があります。テキストが「、...」で終わる場合は、正確にn行より少し長くなります。

次に例を示します。IDを持つTextViewquestionはラップします。

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:shrinkColumns="*">
    <TableRow>
         <TextView
             android:id="@+id/question"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"/>
    </TableRow>
</TableLayout>
于 2011-03-21T22:04:42.060 に答える
3

コードでも機能します:

TableLayout tablelayout = (TableLayout) view.findViewById(R.id.table);
tablelayout.setColumnShrinkable(1,true);

1 は列の数です。

于 2014-09-10T11:08:28.567 に答える
2

多分次のようにしてみてください:

myTextView.setText(Html.fromHtml("On " + stringData1 + "<br> at " + strinData2);

「車椅子」ソリューションのように見えますが、プログラムでテキストを入力することもできますが、私にとってはうまくいきます。

于 2011-03-21T15:44:54.470 に答える