2013-07-24 3 views
4

J'ai un problème avec un pied de page pour la liste (je ne peux pas centrer le pied de page). J'utilise un pied de page pour une liste sans fin. Le problème que j'ai est que le pied de page n'est pas étiré pour correspondre à la largeur de la liste (à la place est en quelque sorte en utilisant wrap_content).Largeur du pied ListView

C'est la mise en page de bas de page:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/footer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:gravity="center" 
    android:padding="10dp" > 

    <ProgressBar 
     android:id="@+id/progressBar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" /> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="5dp" 
     android:text="Loading more..." /> 

</LinearLayout> 

Et voici comment ajouter le pied de page à la listview:

View footerView; 

...  

// Get the custom layout for footer 
     footerView = getActivity().getLayoutInflater(). 
       inflate(R.layout.list_footer_load_more, getListView(), false); 
     LinearLayout footerViewLayout = (LinearLayout) footerView.findViewById(R.id.footer_layout); 
     // Adding custom view to ListView at footer 
     getListView().addFooterView(footerViewLayout, null, false); 

Et voilà comment le résultat final ressemble à: (je peux 't publie des images sur stackoverflow, mais voici un lien externe vers l'image) http://s21.postimg.org/3zkd7pic7/listview_footer_problem.png

J'ai tout essayé pour cente r le pied de page mais rien n'a fonctionné. J'espère que quelqu'un pourra m'aider, parce que cela me stressera pendant un certain temps.

Merci.

Répondre

3

Modifier votre mise en page de bas de page (R.layout.list_footer_load_more) à:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/footer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_horizontal" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <ProgressBar 
      android:id="@+id/progressBar" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" /> 

     <TextView 
      android:id="@+id/textView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="5dp" 
      android:layout_gravity="center_vertical" 
      android:text="Loading more..." /> 

    </LinearLayout> 
</RelativeLayout> 

Changer votre code:

View footerView; 

...  

// Get the custom layout for footer 
footerView = getActivity().getLayoutInflater(). 
      inflate(R.layout.list_footer_load_more, null); 
RelativeLayout footerViewLayout = (RelativeLayout) footerView.findViewById(R.id.footer_layout); 
    // Adding custom view to ListView at footer 
    getListView().addFooterView(footerViewLayout, null, false); 
+0

Malheureusement, il est toujours le même –

+0

@IonutNegru j'ai changé un peu le code . Voyez si cela fonctionne maintenant. – Vikram

+0

@IonutNegru Et, en gonflant 'R.id.footer_layout', utilisez' gonfler (R.layout.list_footer_load_more, null); ' – Vikram

Questions connexes