2013-07-22 2 views
3

Je programmation d'une application pour Android et je vais avoir le problème suivant:ImageView est en train de changer la taille en fonction de l'image (Android)

je dois afficher les images téléchargées via Http dans une Liste contenant et ImageView et texte. Les deux ou les sont contenus dans un LinearLayout:

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

<ImageView 
    android:id="@+id/imagenEvento" 
    android:layout_width="80dp" 
    android:layout_height="80dp" 
    android:scaleType="fitXY" 
    android:adjustViewBounds="true" 
    android:paddingBottom="2dp"  
    android:contentDescription="@string/contenidoImagen"  

    /> 


<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="left" 
    android:padding="10dp" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/titulo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="17sp" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <TextView 
     android:id="@+id/sitio" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="12sp" 
     android:textAppearance="?android:attr/textAppearanceSmall" /> 

    <TextView 
     android:id="@+id/fecha" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="12sp" 
     android:textAppearance="?android:attr/textAppearanceSmall" /> 

</LinearLayout> 

icharge Images dinamically avec différentes tailles et, mais quand je charge certains d'entre eux, la taille de mon ImageView est touché et il ne sera pas respecter ma taille et déclarations de largeur.

J'ai essayé de stabiliser les tailles MAX et MIN, j'ai défini Layout Params dans le code, j'ai mis à jour le Bitmap, mais rien n'a fonctionné.

Dans l'image suivante les cercles jaunes montrent le même espace et le rouge un espace différent entre le ImageView et le fond de la ligne http://imageshack.us/photo/my-images/32/csww.jpg/

Qu'est-ce que je manque?

+0

Nope , cela n'a pas fonctionné, je continue à obtenir les mêmes résultats – n4h1n

+1

Mais ImageVIew conserve sa taille, à droite LinearLayout contenant TextViews change en fonction des lignes –

+0

@MarcinGawel ImageView i s changement de taille je pense. TextViews change en fonction des lignes, c'est vrai, mais cela ne devrait pas affecter la taille d'ImageView – n4h1n

Répondre

3

Vous pouvez essayer ce morceau de code. Si ce travail de force, vous pouvez alors utiliser relativelayout et mettre tout le point de vue de l'image et les textes dans une mise en page et essayer de régler dans cette disposition relative

<ImageView 
    android:id="@+id/imagenEvento" 
    android:layout_width="80dp" 
    android:layout_height="fill_parent" 
    android:scaleType="fitXY" 
    android:adjustViewBounds="true" 
    android:paddingBottom="2dp"  
    android:contentDescription="@string/contenidoImagen"  

    /> 

OU

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

    <RelativeLayout 
     android:id="@+id/relativeLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@android:color/darker_gray" 
     android:layout_alignParentTop="true" > 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      android:src="@drawable/ic_launcher" /> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_marginLeft="16dp" 
      android:layout_toRightOf="@+id/imageView1" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="TextView" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/textView1" 
      android:layout_below="@+id/textView1" 
      android:text="Content Name" /> 

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/textView2" 
      android:layout_below="@+id/textView2" 
      android:text="29/02/2009" /> 
    </RelativeLayout> 

</RelativeLayout> 

enter image description here

+0

Il a bien fonctionné, je viens de changer android: layout_width = « 80dp » android: layout_height = « 80dp », le seul problème est que les ImageViews changent leur taille et je ne veux pas que ça arrive – n4h1n

+0

Okey ya bien Tats –

0

Pourquoi utilisez-vous android: adjustViewBounds si vous voulez des tailles spécifiques pour vous ImageView? Avec Android: adjustViewBounds, votre ImageView va changer sa taille pour conserver les proportions de l'image.

Si vous voulez afficher votre image en vrai 80x80 - supprimer android: adjustViewBounds et changer scaleType à centerCrop. De cette façon, l'image diminuera autant que possible, donc les deux dimensions toucheront les limites d'ImageView et le reste sera rogné.

Ou utilisez scaleType = "centerInside" si vous voulez l'image soit visible entièrement (qui regardera plus laid 100% garantie: D)

De toute façon, android: adjustViewBounds doit aller.

+0

Cela a fonctionné, j'ai fait les changements que vous avez dit et c'est OK! Merci! – n4h1n

Questions connexes