2011-02-18 1 views
0

Je crée un layout et j'ai un en-tête aligné sur le dessus, un pied de page aligné sur le bas et je veux que la vue prenne tout le reste de l'espace disponible au milieu.View widthXheight est égal à l'espace disponible de l'écran

Comment faire cela sans passer explicitement les attributs de hauteur à chaque vue?

Mon XML réelle est:

<?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" 
    orientation="vertical"> 

    <ImageView 
     android:id="@+id/header" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/library_header" 
     android:scaleType="fitXY" /> 

    <ViewFlipper 
     android:id="@+id/content" 
     android:layout_height="0dip" 
     android:layout_width="match_parent" 
     android:layout_weight="1.0" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="44px" 
     android:layout_alignParentBottom="true" 
     android:background="@drawable/library_footer"> 

     <Button 
      android:id="@+id/l_coverflow" 
      android:layout_width="44px" 
      android:layout_height="34px" 
      android:background="@drawable/library_coverflow_deselected" 
      android:layout_gravity="center" android:layout_marginLeft="12px" /> 

     <Button 
       android:id="@+id/l_grid" 
       android:layout_width="36px" 
       android:layout_height="32px" 
       android:background="@drawable/library_grid_deselected" 
       android:layout_marginLeft="12px" 
       android:layout_gravity="center" 
       android:paddingLeft="10px" /> 

     <Button 
       android:id="@+id/l_list" 
       android:layout_width="40px" 
       android:layout_height="32px" 
       android:background="@drawable/library_list_deselected" 
       android:layout_marginLeft="12px" 
       android:layout_gravity="center" /> 
    </LinearLayout> 
</LinearLayout> 
+0

Utilisez-vous un LinearLayout ou un RelativeLayout comme conteneur? –

+0

J'utilise LinearLayout –

Répondre

5

Il est très facile (j'omis l'androïde: namespace prefix par souci de concision):

<LinearLayout 
    orientation="vertical" 
    layout_width="fill_parent" 
    layout_height="fill_parent"> 

    <!-- Header goes here with height=wrap_content --> 

    <MiddleView 
    layout_width="fill_parent" 
    layout_height="0dip" 
    layout_weight="1.0" /> 

    <!-- Footer goes here with height=wrap_content --> 

</LinearLayout> 
+0

N'a pas fonctionné, j'ai mis à jour la question avec mon XML actuel. –

+0

Maintenant, juste l'en-tête apparaît sur mon écran. –

+0

C'est android: orientation = "vertical", vous avez oublié l'android: partie –