11

以下に示すように、ヘッダーとフッターの2つのxmlファイルがあります

header.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#9d1246" >

        <Button
            android:id="@+id/button_backfromreg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/backbtn"
            android:visibility="visible" />
    </LinearLayout>

</LinearLayout>

フッター.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#9d1246" >
    </LinearLayout>

</LinearLayout>

示されているように、メインレイアウトに上記の 2 つのレイアウトを含めました。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#eaedf2"
    android:orientation="vertical" >

    <include
        android:layout_weight="1"
        layout="@layout/header" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_margin="30dp"
        android:layout_weight="1"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:editable="false"
            android:ems="10"
            android:hint="Country"
            android:textColor="#655e5e"
            android:textSize="15sp" >

            <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/editText2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:editable="false"
            android:ems="10"
            android:hint="State"
            android:textColor="#655e5e"
            android:textSize="15sp" />

        <EditText
            android:id="@+id/editText3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:editable="false"
            android:ems="10"
            android:hint="Place Keyword"
            android:textColor="#655e5e"
            android:textSize="15sp" />
    </LinearLayout>

    <include
        android:layout_height="0dp"
        android:layout_weight="1"
        layout="@layout/footer" />

</LinearLayout>

私の問題は、上記のレイアウトを使用すると、フッターが表示されないことです。誰でも私を助けてください。前もって感謝します。

4

3 に答える 3

18

含まれているレイアウトをコンテナーに保持し、重み属性をそのコンテナーのみに設定します。

これは更新されたレイアウトです

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#eaedf2"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <include

            android:layout_height="match_parent"
            android:layout_width="match_parent"
            layout="@layout/header" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_margin="30dp"
        android:layout_weight="1"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:editable="false"
            android:ems="10"
            android:hint="Country"
            android:textColor="#655e5e"
            android:textSize="15sp" >

            <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/editText2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:editable="false"
            android:ems="10"
            android:hint="State"
            android:textColor="#655e5e"
            android:textSize="15sp" />

        <EditText
            android:id="@+id/editText3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:editable="false"
            android:ems="10"
            android:hint="Place Keyword"
            android:textColor="#655e5e"
            android:textSize="15sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <include
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            layout="@layout/footer" />
    </LinearLayout>

</LinearLayout>
于 2013-10-29T07:14:15.243 に答える
-3

weightSum = "3"parentLayoutに渡してこれを試してください

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#eaedf2"
    android:orientation="vertical"
    android:weightSum="3"
 >

また、パラメータをinclude

<include
         android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        layout="@layout/header" />


<include
         android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        layout="@layout/footer" />

これがうまくいくことを願っています

于 2013-10-29T07:15:46.423 に答える