Вопрос

I'm programming an application for Android and i'm having the next problem:

I need to display downloaded Images via Http into a List View containing and ImageView and Text. Both or them are contained in a 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>

Iload Images dinamically with different sizes and, but when i load some of them, the size of my ImageView is being affected and it wont respect my height and width declarations.

I've tried to stablish MAX and MIN sizes, i've defined Layout Params in the code, stablished padding Bottom, rezised the Bitmap but nothing works.

In the next picture the yellow circles show the same space and the red one a different space between the ImageView and the bottom of the row http://imageshack.us/photo/my-images/32/csww.jpg/

What am I missing?

Это было полезно?

Решение

You can try this piece of code. If this dint work then you can use relativelayout and put all the image view and texts in a layout and try to adjust in that relative layout

<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"       

    />

OR

<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

Другие советы

Why do you use android:adjustViewBounds if you want specific sizes for you ImageView? With android:adjustViewBounds your ImageView will change it's size to keep aspect ratio of the image.

If you want to display your image in true 80x80 - remove android:adjustViewBounds and change scaleType to centerCrop. That way, the image will scale down as much ass possible, so the both dimensions will touch ImageView bounds and the rest will be cropped.

Or use scaleType="centerInside" if you want for image to be visible fully (that'll look uglier 100% guarantee :D)

Either way, android:adjustViewBounds must go.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top