2012-03-07 5 views
1

でlayout_centerVertical = "true" の[編集]避けてください:RelativeLayout

考える:私は小さな画面上のテキスト1とテキスト2の間の重複を避けることができますどのように

<?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="match_parent" > 

    <TextView 
     android:id="@+id/text1" 
     android:layout_width="match_parent" 
     android:layout_height="200dip" 
     android:background="#ff00ff00" /> 

    <TextView 
     android:id="@+id/text2" 
     android:layout_width="match_parent" 
     android:layout_height="200dip" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:background="#ffff0000" /> 

</RelativeLayout> 

。重要:重複がある場合

  • ない重複を有することが可能であれば、テキスト2は、画面の垂直方向の中心に正確に表示されるべき

  • 、テキスト2は少し下に移動すべきであるとテキスト1

    下に直接表示することが

答えて

1

子LinearLayoutにandroid:gravity="center_vertical"を追加します。これは親の中心になります。

button_containerのandroid:layout_height="fill_parent"に変更してください。これにより、親の残りの高さを塗りつぶします。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#ffff0000" 
    android:text="TextView" /> 

<LinearLayout 
    android:id="@+id/button_container" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center_vertical" 
    android:orientation="vertical" > 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="test" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="test" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="test" /> 
</LinearLayout> 

+0

おかげで、しかし、ここでbutton_containerはない画面の中央に、残りのスペースの真ん中にある:あなたのコードは、変更後に次のようになります。私は画面の真ん中にそれが必要です(十分なスペースがあれば)。 –

+0

あなたは質問全体を変更しましたが、試行された回答はすべてコンテキスト外になりました。別途ご質問ください。 – Akhil

関連する問題