2011-07-22 3 views
0

J'ai une liste personnalisée qui change de taille lorsque l'on clique sur l'une des lignes, de nouvelles lignes sont ajoutées. Lorsque l'activité est chargée pour la première fois, il n'y a qu'une seule ligne et deux boutons (& suivant) dans un tablelayout. Actuellement, si ma listview est ajoutée à un tablerow &, la ligne 2 contient les boutons. La largeur de mise en page & width est définie sur wrap_content.Redimensionner dynamiquement le tabler

Lorsque de nouvelles lignes sont ajoutées à la liste, la taille de la ligne ne change pas et, en second lieu, elle s'étend pour occuper l'espace réservé aux boutons. Et par conséquent mes boutons disparaissent.

main.xml

<LinearLayout android:orientation="vertical" style="?fill_parent" 
android:layout_weight="1"> 
<TableLayout style="?fill_parent" android:layout_weight="1" > 
<TableRow android:id="@+id/tr1"> 
    <CustomList android:id="@+id/mainview" ndroid:layout_height="wrap_content" 
    android:layout_width="wrap_content" /> 
</TableRow> 
<TableRow android:layout_height="wrap_content" android:layout_width="match_parent"> 
    <Button android:layout_width="wrap_content" android:id="@+id/button1" 
    android:text="@string/buttonPrevious" android:layout_height="wrap_content">   </Button> 
    <Button android:layout_width="wrap_content" android:id="@+id/button2" 
    android:text="@string/buttonNext" android:layout_height="wrap_content"></Button> 
</TableRow> 
</TableLayout> 
</LinearLayout> 

Comment puis-je mettre à jour dynamiquement la taille de ligne lorsque les nouvelles lignes sont ajoutées aux vues.? Merci

+0

Avez-vous une solution JayP? – Merlin

Répondre

1

Replace TableLayout avec un RelativeLayout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <CustomList android:layout_above="@+id/btn_pnl" 
    android:id="@+id/mainview" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" /> 
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/btn_pnl" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@android:color/transparent" 
     android:layout_alignParentBottom="true"> 
     <Button android:layout_width="wrap_content" 
      android:id="@+id/button1" 
      android:text="@string/buttonPrevious" 
      android:layout_height="wrap_content"> 
     </Button> 
     <Button android:layout_width="wrap_content" 
      android:id="@+id/button2" 
      android:text="@string/buttonNext" 
      android:layout_height="wrap_content"></Button> 
    </LinearLayout> 
</RelativeLayout> 

Cette disposition mettra vos boutons en bas de l'écran, tandis que le ListView couvrira tout l'écran.

+0

Cela fonctionne mais l'inconvénient étant que les boutons sont collés au bas de la page tout le temps. Ce que je préférerais, c'est que les boutons descendent vers le bas de la page quand la liste augmente ... toutes les suggestions pour cela – jsp

+0

Vous pouvez ensuite créer votre CustomList layout_height = "wrap_content" et il devrait vous donner la disposition que vous voulez. Mais alors vous aurez des boutons qui sortent de l'écran lorsque la hauteur de la liste dépasse la hauteur de l'écran. – Audrius

0

Ne placez pas votre CustomList dans un tableau, utilisez une disposition linéaire pour maintenir les boutons. Portez une attention particulière aux attributs layout_weight comme indiqué dans le balisage de mise en page suivant

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <CustomList android:id="@+id/mainview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"/> 
    <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/llButtons" android:layout_gravity="bottom" android:layout_weight="0"> 
     <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"></Button> 
     <Button android:text="Button" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"></Button> 
    </LinearLayout> 
</LinearLayout> 
Questions connexes