2013-09-24 4 views
1

Voilà à quoi il ressemble: http://i.imgur.com/navAYXk.jpgToggle est pas centré

Et voici le code responsable de la mise en page: (togglebutton en question est le dernier)

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
      android:id="@+id/controls" 
      android:layout_width="match_parent" 
      android:layout_height="35dp" 
      android:background="@drawable/border" > 

      <ImageButton 
       android:id="@+id/playpause" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.25" 
       android:background="@null" 
       android:src="@drawable/player_play" 
       android:text="play/pause" /> 

      <ImageButton 
       android:id="@+id/prev" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.25" 
       android:background="@null" 
       android:src="@drawable/player_prev" 
       android:text="prev" /> 

      <ImageButton 
       android:id="@+id/next" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.25" 
       android:background="@null" 
       android:src="@drawable/player_next" 
       android:text="next" /> 

      <ToggleButton 
       android:id="@+id/shuffleButton" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.25" 
       android:background="@null" 
       android:button="@drawable/toggle_check" 
       android:layout_gravity="center" 
       android:textOff="" 
       android:textOn="" /> 

     </LinearLayout> 

</LinearLayout> 

Et voici le fichier Toggle_check .xml:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:drawable="@drawable/player_shuffle_on" 
      android:state_checked="true" /> 
    <item android:drawable="@drawable/player_shuffle_off" 
     android:state_checked="false"/> 
</selector> 

Je ne sais pas pourquoi cette image est togglebutton pas centrée, quelqu'un peut me aider?

Répondre

0

Votre mise en page me semble ok. Je vais essayer de remplacer le ToggleButton pour un autre ImageButton, juste pour s'assurer que Android ne pas ajouter un rembourrage automatiquement comme il le fait avec CheckBoxes. Vérifiez également que ni les player_shuffle_on ni les player_shuffle_off png n'ont été accidentellement enregistrés avec un remplissage transparent. Par ailleurs, il n'y a pas besoin de deux LinearLayouts, vous pouvez avoir un seul LinearLayout horizontal comme votre vue racine.

0
Add Gravity-Center to your second Linear Layout: 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
      android:id="@+id/controls" 
      android:layout_width="match_parent" 
      android:layout_height="35dp" 
      *android:gravity="center"* 
      android:background="@drawable/border" > 

      <ImageButton 
       ...