2017-07-16 2 views
0

PROBLEM DESCRIPTION IMAGE. THIS IS WHAT IS DESIRED (CLICK ON THE IMAGE LINK)Impossible d'afficher le bouton ci-dessous une vue liste

J'extraction de données à partir d'une API et de faire une application de nouvelles applications. Chaque page a X nombre d'articles de nouvelles. Disons 10 articles par page. Donc j'utilise un ListView et un ArrayAdapter pour montrer tous les articles sur la 1ère page. Je veux à la fin du 10ème article ci-dessous listView qui dit "PLUS" ou quelque chose comme ça qui charge la page suivante contenant les 10 prochains articles. Maintenant, je travaillais sur l'interface utilisateur et le bouton ne s'affiche pas en dessous de la liste.

J'ai essayé ces scénarios:

  1. Layout_alignparentBotton: Le bouton est bloqué à l'aide parentBottom layout_alignParentBottom mais la liste est et va scrollable sous le bouton que le bouton est fixe, mais la liste est scrollable. Résultat attendu

  2. layout_below: J'ai essayé layout_below et j'ai donné l'ID de la vue liste. Ensuite, le bouton ne s'affiche pas du tout. Je ne sais pas pourquoi. Je me demandais cela comme la solution possible, mais je suppose que je fais quelque chose de mal.

Voici mon XML:

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



    <ListView 
     android:id="@+id/list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" /> 


    <Button 
     android:id="@+id/moreButton" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/list" 
     android:text="More" /> 

</RelativeLayout> 

Ce qui fait l'listView si cela aide (Le XML de l'élément individuel de la liste):

<?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:id="@+id/customListViewID" 
     android:background="@drawable/background_shape_adapter" 
     android:orientation="horizontal"> 

     <ImageView 
      android:id="@+id/newsThumbnailImage" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:scaleType="centerCrop" /> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="3" 
      android:orientation="vertical" 
      android:paddingStart="10dp" 
      android:paddingTop="10dp"> 

      <TextView 
       android:id="@+id/titleNewsTextView" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:maxLines="3" 
       android:text="Title Of News" 
       android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small" 
       android:textColor="#000" /> 

      <TextView 
       android:id="@+id/newsSnippetTextView" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:maxLines="2" 
       android:text="Content Snippet" 
       android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small.Inverse" 
       android:textColor="@color/black_overlay" /> 
     </LinearLayout> 
    </LinearLayout> 


</LinearLayout> 

Répondre

1

Utilisez votre bouton avec alignParentBottom et définissez-le sur invisible et lorsque la vue liste atteint une fin, affichez-le.

private int preLast; 
// Initialization stuff. 
yourListView.setOnScrollListener(this); 

// ... ... ... 

@Override 
public void onScroll(AbsListView lw, final int firstVisibleItem, 
    final int visibleItemCount, final int totalItemCount) 
{ 

switch(lw.getId()) 
{ 
    case R.id.your_list_id:  

     // Make your calculation stuff here. You have all your 
     // needed info from the parameters of this function. 

     // Sample calculation to determine if the last 
     // item is fully visible. 
     final int lastItem = firstVisibleItem + visibleItemCount; 

     if(lastItem == totalItemCount) 
     { 
      if(preLast!=lastItem) 
      { 
       bottomButton.setVisibility(View.VISIBLE); 
       preLast = lastItem; 
      } 
     } 
} 
} 
+0

Merci, cela a fonctionné – Aman

+1

S'il vous plaît donner la référence à d'autres en utilisant la réponse de quelqu'un d'autre.https: //stackoverflow.com/questions/5123675/find-out-if-listview-is-scrolled-to-the-bottom –

0

Essayez d'utiliser un LinearLayout avec une orientation verticale plutôt que RelativeLayout (dans votre premier fichier XML).

+0

La disposition linéaire n'autorise pas layout_below. – Aman

+0

Supprimer layout_below, ce n'est pas nécessaire. – fazega

+0

Non, LinearLayout ne fonctionne pas. – Aman