2012-03-07 7 views
1

[편집]피하십시오 : 감안할 때 RelativeLayout의

에서 layout_centerVertical이 = "true"로 :

<?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> 

어떻게 작은 화면에 텍스트 1, 텍스트 2 사이의 중복을 피할 수 있습니다. 중요 : 중복이있는 경우

  • 겹침에 가능하다면, 텍스트 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