2012-06-19 5 views
0

하나의 선형 레이아웃을 만들고 두 개의 상대 레이아웃을 추가했습니다. 하단의 다른 레이아웃 위에 하나의 레이아웃을 표시하고 싶습니다. 내 문제는 모두 상단에 레이아웃을 표시합니다. 어떻게 바뀌는 지 1 층 위로 가기 다른 하나는 저를 도와주세요.어떻게 하단에 상대 레이아웃을 표시하려면?

XML 코드 :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:background="@drawable/blue" 
    android:orientation="horizontal" > 

    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="55px" 
     android:background="@drawable/testheader" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/header_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:text="settings" 
      android:textColor="@color/white" 
      android:textSize="20sp" /> 

     <Button 
      android:id="@+id/btnReturn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:text="image" /> 

    </RelativeLayout> 

    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="55px" 
     android:background="@drawable/testheader" 
     android:orientation="horizontal" 
     android:layout_alignParentBottom="true" 
     android:layout_gravity="bottom" 
     > 

     <Button 
      android:id="@+id/btnReturn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:text="Return" /> 
    </RelativeLayout> 



</LinearLayout> 
+1

변경 RelativeLayout의로의 LinearLayout. –

답변

2
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:background="@drawable/blue" 

    > 

    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="55px" 
     android:background="@drawable/testheader" 
     android:orientation="horizontal" 

     > 

     <TextView 
      android:id="@+id/header_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="settings" 
      android:textColor="@color/white" 
      android:textSize="20sp" 
      android:layout_centerInParent="true"/> 

     <Button 
      android:id="@+id/btnReturn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="image" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true"/> 

    </RelativeLayout> 


    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="55px" 
     android:background="@drawable/testheader" 
     android:orientation="horizontal" 
     android:layout_alignParentBottom="true" 
     android:layout_gravity="bottom" 
     > 

     <Button 
      android:id="@+id/btnReturn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:text="Return" /> 
    </LinearLayout> 


</RelativeLayout> 

enter image description here

+0

하단보기도 업데이트되었습니다. –

0

vertical에있는 LinearLayout의 방향을 변경 상대 layout.See와

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:background="@drawable/blue" 
    android:orientation="horizontal" > 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="55px" 
     android:layout_alignParentTop="true" 
     android:background="@drawable/testheader" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/header_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:text="settings" 
      android:textColor="@color/white" 
      android:textSize="20sp" /> 

     <Button 
      android:id="@+id/btnReturn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:text="image" /> 

    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="55px" 
     android:background="@drawable/testheader" 
     android:orientation="horizontal" 
     android:layout_alignParentBottom="true" 
     android:layout_gravity="bottom" 
     > 

     <Button 
      android:id="@+id/btnReturn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:text="Return" /> 
    </RelativeLayout> 



</RelativeLayout> 
0

아래의 XML을 Parentalayout을 시도해보십시오

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:background="@drawable/blue" 
    android:orientation="vertical" > 
-1

을 선형 레이아웃으로 변경 수직 방향.

0

부모 레이아웃은 RelativeLayout의이어야한다, 그래서 당신은 다른 사람들이 위에이 같은 바닥에 레이아웃 positionne 수 있습니다

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="55px" 
     android:background="@drawable/testheader" 
     android:alignParentTop ="true" > 

     <TextView 
      android:id="@+id/header_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:text="settings" 
      android:textColor="@color/white" 
      android:textSize="20sp" /> 

     <Button 
      android:id="@+id/btnReturn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:text="image" /> 

    </RelativeLayout> 

    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="55px" 
     android:background="@drawable/testheader" 
     android:orientation="horizontal" 
     android:layout_alignParentBottom="true" 
     android:layout_gravity="bottom" 
     > 

     <Button 
      android:id="@+id/btnReturn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:text="Return" /> 
    </RelativeLayout> 



</RelativeLayout> 
0

enter image description here

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:background="#F0F" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="90dp" 
     android:text="Large Text" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

</RelativeLayout> 

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:background="#F0F" > 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:text="Button" /> 
</RelativeLayout> 

1

을 바꿔주세요.을 RelativeLayout으로 설정 한 다음 두 개의 내부 상대 레이아웃을 만들고 한 세트는 android:layout_alignParentTop="true", 두 번째 세트는 android:layout_alignParentBottom="true"으로 작성한 다음 원하는대로 작동합니다.

관련 문제