1

TextView を紫色の背景の中央に配置する必要がありますここに画像の説明を入力

これは XML です。

<TextView
    android:id="@+id/widget33"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="somePurplePNG"
    android:text="TextView"
    android:gravity="left"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true" />

何か案は?PS: textview をラップして背景を定義するレイアウトを作成できません。

4

5 に答える 5

6

このようにテキストビューの重力を変更します

android:gravity="center_horizontal"

また

android:gravity="center"
于 2012-06-01T09:42:13.127 に答える
1
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

<TextView
    android:id="@+id/widget33"
    android:layout_width="match_parent"
    android:layout_height="64dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:gravity="center"
    android:text="TextView" />

</LinearLayout>    
于 2013-02-12T08:32:06.893 に答える
1

Javaクラスでプログラムによってテキストビュー内のテキストを整列させることができます

TextView YourTextView = (TextView)findViewById(R.id.textViewid);
//This will align text in both horizontal and Vertical of its container
YourTextView.setGravity(Gravity.CENTER);

//Place object in the vertical center of its container
YourTextView.setGravity(Gravity.CENTER_HORIZONTAL);

//Place object in the vertical center of its container
YourTextView.setGravity(Gravity.CENTER_VERTICAL);
于 2017-01-06T14:50:59.097 に答える
1

を使用して解決

android:gravity="center_vertical"
于 2012-06-01T09:41:57.383 に答える