2012-06-19 3 views
0

Я создал один линейный макет, и я добавил два относительных макета. Я хочу показать один макет в верхней части макета внизу. Моя проблема заключается в отображении макета сверху. как изменить 1layout верхнее другое внизу, пожалуйста, помогите мне.Как показать Относительное расположение внизу?

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

Изменить ваш LinearLayout к RelativeLayout. –

ответ

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

Попробуйте Parentalayout с относительной layout.See в XML ниже

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

Измените ориентацию LinearLayout на vertical:

<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

Просто измените свой LinearLayout с RelativeLayout, а затем создайте два внутренних относительных макета и один набор с android:layout_alignParentTop="true" и второй с android:layout_alignParentBottom="true", а затем он будет работать так, как вы хотите.

Смежные вопросы