3

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?

4

2 回答 2

3

你可以试试这段代码。如果这个 dint 工作,那么您可以使用 relativelayout 并将所有图像视图和文本放在布局中,并尝试在该相对布局中进行调整

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

    />

或者

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

在此处输入图像描述

于 2013-07-22T11:58:21.410 回答
0

如果你想为你的 ImageView 提供特定的尺寸,你为什么要使用 android:adjustViewBounds?使用 android:adjustViewBounds 您的 ImageView 将更改其大小以保持图像的纵横比。

如果您想以真正的 80x80 显示图像 - 删除 android:adjustViewBounds 并将 scaleType 更改为 centerCrop。这样,图像将尽可能缩小,因此两个维度都将触及 ImageView 边界,其余的将被裁剪。

或者,如果您希望图像完全可见,请使用 scaleType="centerInside"(这会看起来更丑 100% 保证:D)

无论哪种方式, android:adjustViewBounds 都必须去。

于 2013-07-22T11:52:12.760 回答