2013-10-10 9 views
0

Afin de prendre tout l'espace de l'écran, je fait cette mise en page:mise en page personnalisée du poids en utilisant Android

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="2" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="1" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/tv_detail_placename" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center_vertical|center_horizontal" 
      android:text="zeudhzeid" /> 

     <TextView 
      android:id="@+id/tv_detail_description" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center_vertical|center_horizontal" 
      android:text="Descr d zedezdezdzedez dez dezd" /> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:orientation="horizontal" > 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" /> 
     </LinearLayout> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="1" 
     android:orientation="vertical" > 

     <!-- Map --> 

     <fragment 
      android:id="@+id/map_detail" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      class="com.google.android.gms.maps.SupportMapFragment"/> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:orientation="horizontal" > 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="Do" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="Do" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="Do" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="Do" /> 
     </LinearLayout> 
    </LinearLayout> 

</LinearLayout> 

éclipse la mise en page semble être bon et est la vue donnée par Graphica Mise en page:

enter image description here

Mais en vrai, je suis ceci dans mon téléphone (Samsung Galaxy S3):

enter image description here

Et pour info, j'utilise ActionBarSherlock pour le thème.

+0

Essayez de définir la hauteur du fragment '0dip'. –

Répondre

0

essayez de régler weight de Fragment par votre requirment.

<fragment 
     android:id="@+id/map_detail" 
     android:layout_width="match_parent" 
     android:layout_height="0dip" 
     android:layout_weight="2" 
     class="com.google.android.gms.maps.SupportMapFragment"/> 
+0

Cela fonctionne oui! Mais maintenant, ma carte est trop courte. Avez-vous une solution pour garder ce système de poids mais juste diminuer la valeur des boutons? – eento

0

Vous déclarez un nouveau ScrollBar en XML et il contient tout ce qu'il contient. Mappe la dimension mesurée par défaut plus grande que priview. De même;

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent">  

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="2" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="1" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/tv_detail_placename" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center_vertical|center_horizontal" 
      android:text="zeudhzeid" /> 

     <TextView 
      android:id="@+id/tv_detail_description" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center_vertical|center_horizontal" 
      android:text="Descr d zedezdezdzedez dez dezd" /> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:orientation="horizontal" > 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" /> 
     </LinearLayout> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="1" 
     android:orientation="vertical" > 

     <!-- Map --> 

     <fragment 
      android:id="@+id/map_detail" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      class="com.google.android.gms.maps.SupportMapFragment"/> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:orientation="horizontal" > 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="Do" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="Do" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="Do" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="Do" /> 
     </LinearLayout> 
    </LinearLayout> 

</LinearLayout> 
</ScrollView> 
+0

Merci, mais ce Scrollview ne fonctionne pas correctement avec mes paramètres de poids et un scrollview combiné avec google map == mauvais – eento

+0

Vous devez définir une taille fixe à votre fragment – nurisezgin

0

N'oubliez pas de régler la hauteur ou la largeur sur 0dp lorsque vous utilisez un poids. Peut-être que c'est le problème.
Par exemple, vous devez remplacer cette

  <Button 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Do" /> 


avec ce

  <Button 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Do" /> 

Aussi, vous devez savoir que les poids imbriqués ne sont pas bonnes pour la performance. Vous devriez reconsidérer votre mise en page.

1
<fragment  
      android:id="@+id/map_detail" 
      android:layout_width="match_parent" 
      android:layout_height="0dip" 
      android:layout_weight="2" 
      class="com.google.android.gms.maps.SupportMapFragment" /> 

J'espère que cela va le résoudre.

Questions connexes