Question

J'ai essayé de créer un RelativeLayout avec un en-tête, corps (liste) et pied de page. Je veux l'en-tête soit au-dessus de tout (aligné en haut), le corps (liste) d'être sous l'en-tête (lors du défilement) et le pied de page (aligné en bas) pour être au-dessus du corps (liste) - uniquement lorsqu'elle est visible.

J'ai réussi à le faire PARFAITEMENT quand il s'agit de la façon dont les choses sont, mais apparemment la mise en page XML est la cause des problèmes que j'ai eu en cliquant sur listItems ( voir ici , et ).

Afin de résoudre les problèmes, je devais envelopper le ListView avec LinearLayout et le mettre entre l'en-tête et le pied de page (dans le fichier XML). Cela résout les problèmes en cliquant listItems mais crée un nouveau problème - le pied de page cache le dernier élément ListView, même si la liste ne va sous l'en-tête lors du défilement vers le bas

.

Je suis à peu près désespérée ici: \

Ceci est le XML qui crée la mise en page parfaite, mais provoque la liste de questions Point cliquant sur:

<?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:orientation="vertical"
    android:background="#ffffff"
    >
    <RelativeLayout
        android:background="@drawable/top_background"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:id="@+id/top_control_bar"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text="Droidmarks"
            android:layout_alignParentLeft="true"
            android:layout_toLeftOf="@+id/add_bookmark"
            android:textSize="20dip"
            android:textColor="#a0cb26"
            android:shadowColor="#7a9b1b"
            android:shadowRadius="5"
            android:layout_marginLeft="5dip"
            android:gravity="left|center" />
        <Button
            android:id="@+id/add_bookmark"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|center"
            android:layout_alignParentRight="true"
            android:text="Add"
        />
    </RelativeLayout>
    <LinearLayout
        android:id="@+id/bottom_control_bar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@drawable/top_background"
        android:visibility="invisible"
        >
        <Button
            android:id="@+id/test"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|center"
            android:layout_alignParentRight="true"
            android:text="Add"
        />
    </LinearLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/top_control_bar"
        android:layout_above="@id/bottom_control_bar"
        android:drawSelectorOnTop="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:cacheColorHint="#ffffff"
        android:listSelector="@drawable/selected_item"
        />
    <TextView android:id="@android:id/empty" android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="No Bookmarks found. You can add one by clicking the star."
        android:layout_below="@id/top_control_bar" android:layout_above="@id/bottom_control_bar" />
</RelativeLayout>

Voici le code XML qui cache la dernière liste d'article mais résout les problèmes cliquants:

<?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:orientation="vertical"
    android:background="#ffffff"
    >
    <RelativeLayout
        android:background="@drawable/top_background"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:id="@+id/top_control_bar"
        android:layout_alignParentTop="true"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text="Droidmarks"
            android:layout_alignParentLeft="true"
            android:layout_toLeftOf="@+id/add_bookmark"
            android:textSize="20dip"
            android:textColor="#a0cb26"
            android:shadowColor="#7a9b1b"
            android:shadowRadius="5"
            android:layout_marginLeft="5dip"
            android:gravity="left|center" />
        <Button
            android:id="@+id/add_bookmark"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|center"
            android:layout_alignParentRight="true"
            android:text="Add"
        />
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/listArea"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@id/top_control_bar"
        >
        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:drawSelectorOnTop="false"
            android:cacheColorHint="#ffffff" />
        <TextView android:id="@android:id/empty" android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="No Bookmarks found. You can add one by clicking the star." />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottom_control_bar"
        android:layout_above="@id/listArea"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@drawable/top_background"
        android:orientation="horizontal"
        android:visibility="visible"
        >
        <Button
        android:id="@+id/test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right|center"
        android:layout_alignParentRight="true"
        android:text="Add"
    />
    </LinearLayout>
</RelativeLayout>

Je serais reconnaissant toute aide pour trouver en quelque sorte une solution pour les problèmes!

Merci!

Était-ce utile?

La solution

Puis-je demander pourquoi vous utilisez un RelativeLayout du tout pour le conteneur? Il semble comme un endroit idéal pour simplement utiliser un LinearLayout avec une zone centrale pondérée (le listview) qui est mis en place pour prendre tout le secteur restant après l'en-tête wrap_height-set et pied de page. RelativeLayouts sont parfaits pour simplifier profondément imbriquées mises en page qui contiennent les éléments horizontaux et verticaux, mais votre couche externe ici ne contient que 3 éléments verticaux de toute façon, donc aller avec un LinearLayout avec orientation:vertical à moins que je me manque quelque chose ici.

EDIT: En bref, essayez ceci; cela devrait vous donner un en-tête de hauteur fixe, un pied de page hauteur d'emballage, et la zone centrale en prenant tout l'espace restant. Assurez-vous que la mise en page externe est réglée à la hauteur de fill_parent et la zone centrale est fixé à une hauteur fixe mais avec un layout_weight="1". J'aime utiliser « 0px » pour la layout_height de base lorsque j'utilise layout_weight juste pour le garder clair pour moi quand je reviens et relis plus tard.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#ffffff"
    >
    <RelativeLayout
        android:background="@drawable/top_background"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:id="@+id/top_control_bar"
        > <!-- snip - inner contents unchanged -->
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/listArea"
        android:layout_width="fill_parent"
        android:layout_height="0px"
        android:layout_weight="1"
        android:orientation="horizontal"
        ><!-- snip - inner contents unchanged -->
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottom_control_bar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/top_background"
        android:orientation="horizontal"
        android:visibility="visible"
        ><!-- snip - inner contents unchanged -->
    </LinearLayout>
</LinearLayout>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top