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

7 回答 7

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>

在此处输入图像描述

于 2012-06-19T13:56:27.043 回答
1

只需更改您的LinearLayoutwith RelativeLayout,然后创建两个内部相对布局,一组 withandroid:layout_alignParentTop="true"和第二个 with android:layout_alignParentBottom="true",然后它将按照您的意愿工作。

于 2012-06-19T13:55:14.733 回答
0

尝试使用相对布局的 Parentallayout。请参阅下面的 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>
于 2012-06-19T13:50:33.363 回答
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" >
于 2012-06-19T13:50:49.197 回答
0

父布局应该是一个 RelativeLayout ,所以你可以像这样在顶部和底部放置其他布局:

    <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>
于 2012-06-19T13:53:54.843 回答
0

在此处输入图像描述

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

于 2012-06-19T13:54:51.813 回答
-1

在线性布局中,将方向更改为垂直。

于 2012-06-19T13:52:50.893 回答