3

新しい InfoWindow (google maps api v2) を構築しており、レイアウトを完璧にしようとしています。そのレイアウトの一部は次のとおりです。

  <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
  android:id="@+id/txtInfoWindowName"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center_horizontal"
  android:ellipsize="end"
  android:singleLine="true"
  android:textColor="#ff000000"
  android:textSize="14dp"
  android:textStyle="bold"/>
<TextView
  android:id="@+id/txtInfoWindowObstacles"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:ellipsize="end"
  android:maxLength="32"
  android:lines="1"
  android:singleLine="true"
  android:textColor="#ff7f7f7f"
  android:textSize="14dp"/>

さて、問題はandroid:ellipsize="end". 、最後に 3 つのドットを描画する必要がありますが、それを行いません。今、私はこのようなものを得ています:

TextTextTextTextTe

これの代わりに:

TextTextTextTextTe...

layout_width="wrap_content" を使用しているという事実と関係があると思います。しかし、私は LinearLayout を使用しているので、それが必要です

4

2 に答える 2

9

私はあなたのコードを試してみましたが、属性を持つ2番目のTextViewを除いて、正常に動作しますandroid:maxLength="32"。この場合、32文字の制限のためにテキストを省略できません。しかし、それを削除すると、期待どおりに機能します。

于 2013-01-05T21:05:15.987 に答える
3

別のオプションがあります。次のようなコードから文字列をフォーマットできます。

private static final int STR_MAX_CHAR_COUNT = 32;

private String formatString(String stringToFormat) {
    if(stringToFormat.length() > STR_MAX_CHAR_COUNT){
        stringToFormat = stringToFormat.substring(0, STR_MAX_CHAR_COUNT - 1) + "...";
    }
    return stringToFormat;
}

そして、次のように文字列を設定するだけです:

String newText = "some long-long text";
mTextView.setText(formatString(newText))
于 2013-05-31T08:59:49.903 に答える