2011-06-24 2 views
2

J'ai un problème très inhabituel; J'ai quelques ToggleButtons à l'intérieur d'une disposition linéaire empilée horizontalement. Le texte à l'intérieur (texton, textOff) des boutons n'est pas centrage, et après avoir joué un peu avec paddingLeft, je trouve que 15% de chaque bouton sur le côté droit est quelque chose d'une « zone morte », ce qui signifie le texte est l'emballage quand il frappe - cela expliquerait pourquoi il ne se centre pas correctement.texte Android à l'intérieur du centre ToggleButton wont

Voici le XML:

 <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content">   
     <LinearLayout 
      android:id="@+id/buttons" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:padding="6dip" 
      android:weightSum="1.5" 
      android:background="#0094d2" 
      android:orientation="horizontal"> 
      <ToggleButton 
       android:id="@+id/button1" 
       android:layout_weight=".5" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textColor="@color/off_white" 
       android:textStyle="bold" 
       android:textOn="Button On" 
       android:textOff="Button Off" 
       android:background="@drawable/toggle_states"/> 
      <ToggleButton 
       android:id="@+id/button2" 
       android:layout_weight=".5" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textColor="@color/off_white" 
       android:textStyle="bold" 
       android:textOn="Button On" 
       android:textOff="Button Off" 
       android:background="@drawable/toggle_states"/> 
      <ToggleButton 
       android:id="@+id/button3" 
       android:layout_weight=".5" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textColor="@color/off_white" 
       android:textStyle="bold" 
       android:textOn="Button On" 
       android:textOff="Button Off" 
       android:background="@drawable/toggle_states"/>     
     </LinearLayout> 
     <View android:background="#999999" android:layout_height="1dip" android:id="@+id/divider" android:layout_below="@+id/buttons" android:layout_width="fill_parent"/> 
      <ListView 
       android:id="@+id/listview" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:focusable="true" 
       android:divider="#cccccc" 
       android:dividerHeight="1dip"      
       android:layout_below="@+id/divider" 
       android:fadingEdge="none"/> 
    </RelativeLayout> 

Link to Image, I'm too new so I can't add images yet ><

J'ai essayé le réglage de la gravité dans la mise en page et les boutons à center_horizontal ainsi .. De toute évidence, il n'a pas aidé.

Des idées?

+0

et cela aussi chaque ToggleButton: android: gravité = « center » –

Répondre

1

je copier/coller dans Eclipse et obtenu:

enter image description here

Je n'ai pas votre dessinables, donc je ne peux les regarder, mais je pense que c'est votre problème. Utilisez-vous 9 graphiques patch pour votre bouton, sinon un coup d'oeil à ce lien: http://developer.android.com/guide/developing/tools/draw9patch.html

+0

J'utilise 9 graphiques patch, et vous êtes c'est vrai ... ça a quelque chose à voir avec ça. Je vais poster mes boutons lundi, et jouer avec eux moi-même pour voir si je peux contourner ce problème. Je – Vorathe

+0

uploadés mes boutons à bascule ici: [lien] (http://i.imgur.com/iudpn.png) Les deux premiers sont les fichiers 9patch, et le fond 2 sont les fichiers normaux. Cela doit avoir quelque chose à voir avec la façon dont je les ai vus. – Vorathe

+0

Cool, je suis très occupé aujourd'hui, donc je vais essayer de jeter un oeil à eux pour plus tard et vous recontacterons. – Kenny