2017-02-01 12 views
0

私のすべてのTextViewがRelativeLayout内で垂直方向にセンタリングされることを期待していましたが、これはロゴ1の場合のみです。他は、後者の上部に固定されています。なぜ重力が私のすべての意見を中心にしていないのですか?

Image

ここに私のレイアウトです:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="72dp" 
android:gravity="center_vertical"> 

<TextView 
    android:id="@+id/logo" 
    android:layout_width="40dp" 
    android:layout_height="40dp" 
    android:text="TextView" /> 

<TextView 
    android:id="@+id/stop" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toEndOf="@+id/logo" 
    android:layout_toRightOf="@+id/logo" 
    android:text="TextView" /> 

<TextView 
    android:id="@+id/eta" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toEndOf="@+id/stop" 
    android:layout_toRightOf="@+id/stop" 
    android:text="TextView" /> 

<TextView 
    android:id="@+id/direction" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/stop" 
    android:layout_toEndOf="@+id/logo" 
    android:layout_toRightOf="@+id/logo" 
    android:text="TextView" /> 

答えて

1

属性、次のようにレイアウトするlayout_toEndOfを実行:の最後に

体位、このビューの開始エッジを指定されたアンカービューID。 Link

すべてのTextView sがエッジがlogoの終了に合わせ始めることを意味します。 開始点として、すべてlayout_toEndOf属性を削除してください。

+--------------+ 
|    | +-----------+ 
|    | | stop | 
|    | +-----------+ +-----------+ 
|  logo  |/* no space */ | eta | 
|    | +-----------+ +-----------+ 
|    | | direction | 
|    | +-----------+ 
+--------------+ 

がより正確に、logoが垂直方向に中央揃えされ、etaと同じ:

次に、あなたのレイアウトは、次のようになります。あなたのレイアウトコードは、とdirectionを直接logoの右に配置するので、directionstop以下です。

関連する問題