0

1つの線形レイアウトを作成し、2つの相対レイアウトを追加しました。あるレイアウトを上に、別のレイアウトを下に表示したいと思います。私の問題は、両方のレイアウトが上部に表示されることです。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>
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

を変更LinearLayoutしてRelativeLayoutから、2つの内部相対レイアウトと1つのセットを作成しandroid:layout_alignParentTop="true"、2つ目のセットを作成するとandroid:layout_alignParentBottom="true"、希望どおりに機能します。

于 2012-06-19T13:55:14.733 に答える
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 に答える
0

相対レイアウトでParentalayoutを試してください。以下の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 に答える
-1

線形レイアウトで、向きを垂直に変更します。

于 2012-06-19T13:52:50.893 に答える