1

既に中央に配置された TextView でテキストを中央に配置する際に問題が発生しました。

それがレイアウトです:

<RelativeLayout>... 
<ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:src="@drawable/w0"
    android:layout_margin="10dip"
    android:background="@color/green1"
    />

<TextView
    android:id="@+id/temperature"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignBottom="@id/image"
    android:layout_alignTop="@id/image"
    android:layout_toRightOf="@id/image"
    android:text="15º"
    android:textSize="60dip"
    style="bold"
    android:textColor="@color/blue"
    android:gravity="center"
    android:layout_marginLeft="7dip"
    android:background="@color/green1"
    />

<TextView
    android:id="@+id/min_temperature"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@id/temperature"
    android:layout_toRightOf="@id/temperature"
    android:text="M 21º"
    android:textSize="20dip"
    style="bold"
    android:textColor="@color/blue"
    android:layout_marginLeft="5dip"
    android:background="@color/orange1"
    />

<TextView
    android:id="@+id/max_temperature"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/temperature"
    android:layout_toRightOf="@id/temperature"
    android:text="m 10º"
    android:textSize="20dip"
    style="bold"
    android:textColor="@color/blue"
    android:layout_marginLeft="5dip"
    android:background="@color/orange2"
    />

そして、それが表示されたレイアウト イメージです。

レイアウトイメージ

私が理解していないのは、15º が TextView の中心にない理由です。問題は、TextView が alignTop と alignBottom を使用して中心を強制されているためですが、なぜ機能しないのかわかりません。いくつかの入れ子レイアウトを使用してこれを解決できることはわかっていますが、RelativeLayout のみを使用して解決するか、それが不可能な場合は理由を理解することを好みます。

また、現在あるように、最大​​および最小の TextView を 15 度のテキスト (TextView ではない) の上部と下部に揃えるソリューションもあります。

4

1 に答える 1

0

また、現在のように、最大​​および最小のTextViewを15ºテキスト(TextViewではない)の上部と下部に揃えるソリューションもあります。

  • 私はそうは思わない。ビューが表す実際のボックスに関連するもののみを作成できます。また、TextViewの場合、ボックスはテキストよりも大きくなります。あなたが行うどんな関係も、テキストがどこにあるか、またはそれがどのように見えるかに関係なく、ボックスの位置を使用することになります。

使ってみてください

android:layout_centerVertical = "true"

あなたが今持っている重力に加えてあなたの温度TextViewに。

于 2012-05-07T20:13:29.840 に答える