2011-01-12 7 views
1

Je ne comprends pas très bien RelativeLayout, je ne comprenais pas pourquoi cette XML (il représente un élément d'un listview):Disposition relative

<?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" 
    android:background="@drawable/sfumatura_riga" 
    > 

     <ImageView 
     android:id="@+id/featured_new_image" 
     android:layout_alignParentLeft="true"   
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/no_foto" 

     /> 

     <LinearLayout 
     android:layout_toRightOf="@id/featured_new_image" 
     android:orientation="vertical" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="5dp" 
     > 

     <TextView 
      style="@style/featured_new_title" 
      android:id="@+id/featured_city" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="10dp" 


     /> 

     <TextView 
      style="@style/featured_name_country" 
      android:id="@+id/featured_country" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
     /> 




    </LinearLayout> 

    <TextView 
      style="@style/featured_date" 
      android:id="@+id/featured_date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:layout_marginRight="5dp" 
      android:layout_alignParentRight="true" 
     /> 



</RelativeLayout>       

Je rencontre ce résultat, pourquoi trop de marge à le bas de la rangée? alt text

+0

Si vous avez essayé de modifier le layout_height de la mise en page relative à wrap_content, cela fonctionne-t-il? – xandy

+0

je ne reçois rien de mal dans ce xml. –

+0

J'ai essayé avec ce xandy, mais ne fonctionne pas! – pedr0

Répondre

2

je regardais principalement à deux choses:

  1. Dans la disposition relative, changement android:layout_height="fill_parent" to android:layout_height="wrap content"
  2. Je suppose que l'arrière-plan est juste un dégradé. Cependant, s'il s'agit d'une image, il est possible qu'elle soit trop grande et que toute la ligne soit étirée verticalement. !
+0

Puis-je résoudre cette situation? – pedr0

+0

Voulez-vous dire nr 2? Si oui, coupez simplement l'image ou utilisez un dégradé :). Si c'est déjà un dégradé, cela ne vous aidera pas beaucoup. –

0

Merci atl tout ce que je le résoudre en remplaçant le RelativeLaoyout avec un LinearLayout, je partage la solution et j'espère aider quelqu'un qui ont les mêmes problèmes:

<ImageView 
    android:id="@+id/featured_new_image" 
    android:layout_width="120dp" 
    android:layout_height="fill_parent" 
    android:src="@drawable/no_foto" 

    /> 

<LinearLayout 
    android:orientation="vertical" 
    android:layout_weight="1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="5dp" 
    > 

    <TextView 
     style="@style/featured_new_title" 
     android:id="@+id/featured_city" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="5dp" 
     android:layout_marginTop="10dp" 


    /> 

    <TextView 
     style="@style/featured_name_country" 
     android:id="@+id/featured_country" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
    /> 




</LinearLayout> 

<TextView 
     style="@style/featured_date" 
     android:id="@+id/featured_date" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="5dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right" 
    /> 

Questions connexes