2012-07-30 4 views
0

J'essaie d'afficher une conception d'interface utilisateur à deux volets. J'essaie d'ajouter deux fragments dans une disposition linéaire avec un poids. Cependant, la disposition linéaire semble ignorer le poids. Comment puis-je le corriger ?? MerciDeux fragments ne peuvent pas peser dans la disposition linéaire?

[Lien:] http://dl.dropbox.com/u/78582670/twopanes.png

ma mise en page:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="horizontal" > 

<fragment 
    class="com.usci.view.fragment.CatalogFragment" 
    android:id="@+id/fragment_catalog" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_weight="0.2"> 
</fragment> 

<fragment 
    class="com.usci.education.TestFragment1" 
    android:id="@+id/fragment_test" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_weight="0.8"> 
</fragment> 

</LinearLayout> 

Solution:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="horizontal" > 

<fragment 
    class="com.usci.view.fragment.CatalogFragment" 
    android:id="@+id/fragment_catalog" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="8"> 
</fragment> 

<fragment 
    class="com.usci.education.TestFragment1" 
    android:id="@+id/fragment_test" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="2"> 
</fragment> 

</LinearLayout> 
+0

essayer de donner poids 2 et 8 respectivement – rajpara

+0

essayer. Mais, pas je veux. En fait, je veux vraiment peser le premier fragment à 8. –

+0

puis l'échanger, essayez et erreur mec. – rajpara

Répondre

4

toujours, lorsque vous utilisez des poids, définissez la largeur/hauteur (des enfants) à 0px, et préfèrent des entiers pour les poids.

donc, la solution est:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" > 

<fragment 
    class="com.usci.view.fragment.CatalogFragment" 
    android:id="@+id/fragment_catalog" 
    android:layout_width="0px" 
    android:layout_height="match_parent" 
    android:layout_weight="2"> 
</fragment> 

<fragment 
    class="com.usci.education.TestFragment1" 
    android:id="@+id/fragment_test" 
    android:layout_width="0px" 
    android:layout_height="match_parent" 
    android:layout_weight="8"> 
</fragment> 

</LinearLayout> 
+0

Wow! Fonctionne parfaitement Merci –

+0

Pas toujours - Je crois que vous pourriez parfaitement assigner un 'layout_width' de 200dp et mettre' layout_weight' pour distribuer l'espace restant sur le 200dp. – sstn

+0

@sstn Lint met en garde contre une telle chose qu'il est inutile de faire des calculs supplémentaires pour rien, mais peut-être que je ne vous ai pas compris ou que vous n'avez pas compris ma réponse –

0

Avec moi travaille en mettant 20,80 .. aussi essayer 0.8,0.2:

<fragment 
class="com.usci.view.fragment.CatalogFragment" 
android:id="@+id/fragment_catalog" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:layout_weight="0.8"> 
</fragment> 

<fragment 
    class="com.usci.education.TestFragment1" 
    android:id="@+id/fragment_test" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_weight="0.2"> 
</fragment> 
+0

Impossible de travailler = [... –

0

Set android: layout_width et android: match_parent valeur layout_height, alors par exemple mis android: layout_weight (1 fragment et 2 fragment) Valeur 1

+0

Diviser deux fragments en deux mêmes dimensions –

+0

Oui Pour modifier le poids des fragments, par exemple pour le 1er poids de jeu de fragments 1 et pour le deuxième poids de jeu de fragments 8, jouer avec le poids: – Vladimir

Questions connexes