0

テキストビューのアンカーポイント/原点を中心に変更する方法が見つかりません。フォントサイズを大きくしようとしていますが、左上のポイントではなく、テキストビューの中心から大きくしたいです。

編集:画像で更新

青:起源

紫:センター

原点が 1 & 2 のように左上にある場合、ビューが大きくなると中心が 0,0 からずれます。

3 と 4 のように中心点が移動しないようにしたいのですが、3 が 4 になった場合でも、中心は同じになります。

ここに画像の説明を入力

4

2 に答える 2

2

これはあなたが望むものだと思います....

<TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:gravity="center"
    android:text="Large Text"
    android:textSize="30dp" />
于 2013-10-28T20:48:14.883 に答える
0

本当に希望が役立つ例を貼り付けます。

// テキスト ペイントを作成する

Paint text = new Paint();

// テキスト プロパティを定義します。

text.setColor(Color.GRAY);
text.setStyle(Style.FILL);
text.setFakeBoldText(true);
text.setAntiAlias(true);
text.setTextSize((float) (30));
text.setAlpha(95);

// 私の「キャンバス」(実際にはサブキャンバスのようなもの) の幅は 120 です

// Y 軸を中心に

int yPos = (int) (yTarget - ((text.descent() + text.ascent()) / 2));

// X 軸を中心に

int xPos = (int) (120/2 - text.measureText("+.25°")/2);

// 正しい位置にテキストを書き込む:

canvas.drawText("+.25°", xPos, yPos, text);
于 2014-03-05T13:27:53.957 に答える