2010-08-18 6 views
2

Mon projet fonctionnait correctement lorsque le texte de mes boutons s'affichait soudainement verticalement. Je veux dire au lieu de map_infobutton afficherLe texte du bouton apparaît vertical

Info 

il déployait

I 
n 

avec le f et o au-delà des limites du bouton, même si je l'ai indiqué height = wrap_content dans le TableLayout contenant le boutons.

Il apparaît bien dans l'onglet Mise en page éclipse, et apparaît uniquement verticale dans l'émulateur (pas essayé sur le matériel cible)

getPaddingLeft pour l'un des boutons revient 11 à différents points dans le code. Je ne sais pas d'où ça vient, mais l'espacement semble plus grand que ça de toute façon. J'avais trois boutons et j'en ai pris un, mais le problème existait avec les deux et trois boutons.

Ma mise en page est:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TextView 
    android:id="@+id/map_header" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:paddingTop="8px" 
    android:paddingBottom="8px" 
    android:gravity="center" 
    android:textColor="@color/header_foreground" 
    android:background="@color/header_background" 
    android:text="@string/map_header"/> 
    <TableLayout 
    android:id="@+id/map_footer" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:paddingTop="4px" 
    android:paddingLeft="2px" 
    android:paddingRight="2px" 
    android:stretchColumns="*" 
    android:textColor="@color/footer_foreground" 
    android:background="@color/footer_background"> 
    <TableRow> 
     <Button 
     android:id="@+id/map_infobutton" 
     android:layout_width="0px" 
     android:layout_weight="1" 
     android:text="@string/map_infobutton" /> 
     <Button 
     android:id="@+id/map_selectbutton" 
     android:layout_width="0px" 
     android:layout_weight="1" 
    android:text="@string/map_selectbutton" /> 
</TableRow> 
    </TableLayout> 
    <LinearLayout 
    android:id="@+id/map_selectiondetails" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@id/map_footer" 
    android:orientation="horizontal" 
    android:gravity="center" 
    android:textColor="@color/main_foreground" 
    android:background="@color/main_background" > 
    <TextView 
     android:id="@+id/map_selectionname" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingRight="4px" 
     android:textColor="@color/main_foreground" 
     android:background="@color/main_background"/> 
    <TextView 
     android:id="@+id/map_selectiondistance" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingLeft="4px" 
     android:paddingRight="4px" 
     android:textColor="@color/main_foreground" 
     android:background="@color/main_background"/> 
    <TextView 
     android:id="@+id/map_selectionvar1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingLeft="4px" 
     android:paddingRight="4px" 
     android:textColor="@color/main_foreground" 
     android:background="@color/main_background"/> 
    <TextView 
     android:id="@+id/map_selectionvar2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingLeft="4px" 
     android:paddingRight="4px" 
     android:textColor="@color/main_foreground" 
     android:background="@color/main_background"/> 
    <TextView 
     android:id="@+id/map_selectionvar3" 
    android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingLeft="4px" 
     android:textColor="@color/main_foreground" 
     android:background="@color/main_background"/> 
     </LinearLayout> 
     <SurfaceView 
     android:id="@+id/map_map" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_above="@id/map_selectiondetails" 
     android:layout_below="@id/map_header" 
     android:clickable="true"/> 

    </RelativeLayout> 

Toutes les idées? Aussi si vous avez des commentaires sur la façon dont je crée la mise en page, comme je suis nouveau à cela et il semble qu'il y ait beaucoup d'options disponibles, mais j'essaie de le rendre aussi simple que possible.

+0

Votre mise en page ne fait pas ce que vous décrivez sur mon motorola droid courir 2.2 et mes emu en cours d'exécution 2.1. Il est possible qu'une nouvelle version ne soit pas correctement installée sur l'emu. Essayez un projet propre et redéployez et si cela ne fonctionne pas, recréer l'image emu. – Qberticus

Répondre

1

J'ai eu un problème similaire.

Je vois que vous avez plusieurs boutons que vous voulez avoir la même largeur, donc vous spécifiez la largeur du bouton comme "0px" et le poids comme "1". C'est exactement ce que j'ai fait.

Lorsque je place le texte du bouton dans le fichier XML, les choses se passent bien. Cependant, j'ai un bouton qui change est le texte selon qu'un processus est en cours ou non. Dans mon cas, il est similaire à la situation où un bouton bascule de "Démarrer ..." à "Arrêter ..." Après que le texte change, il imprime verticalement et seulement la première ou les deux premières lettres de chaque bouton sont affichées. Après avoir lu votre message, il m'est apparu que le texte était peut-être réglé avant que la largeur du bouton n'ait été déterminée, et qu'il ne soit pas mis à jour lorsque la largeur du bouton change en fonction du "poids".

je l'ai modifié de telle sorte que chaque bouton, il lit maintenant:

android:layout_width="fill_parent" au lieu de « 0px »

En théorie, cela devrait avoir le même effet. Cependant, en pratique, la largeur du bouton est ajustée avant la mise à jour du texte. Le comportement est maintenant correct.

Rob

+0

Je pense que vous avez raison, mais le changement que vous montrez n'a pas fonctionné. Je vais continuer à essayer dans ce sens, merci – FrinkTheBrave

Questions connexes