简体   繁体   English

从网络下载的列表视图中行的图像应更小

[英]Image downloaded from web for row in listview smaller as it should be

I have a lisview, every row is defined in own xml file: 我有一个lisview,每一行都在自己的xml文件中定义:

 <?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="120dip"
android:padding="6dip" >


<ImageView
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:duplicateParentState="true"
    android:scaleType="fitCenter" />

<TextView
    android:id="@+id/ime"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/icon"
    android:layout_below="@+id/icon"
    android:layout_marginTop="19dp"
    android:text="TextView" />

<TextView
    android:id="@+id/cena1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/icon"
    android:layout_marginLeft="56dp"
    android:layout_toRightOf="@+id/ime"
    android:text="TextView" />

<Button
    android:id="@+id/gumb_klic"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/ime"
    android:layout_alignParentRight="true"
    android:layout_marginLeft="25dip"
    android:layout_marginRight="5dip"
    android:layout_marginTop="10dip"
    android:background="@drawable/call_button"
    android:focusable="false"
    android:focusableInTouchMode="false" />

<TextView
    android:id="@+id/razdalja"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/ime"
    android:layout_alignBottom="@+id/ime"
    android:layout_alignLeft="@+id/cena1"
    android:layout_marginTop="10dip"
    android:text="TextView" />

<TextView
    android:id="@+id/cena2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/cena1"
    android:layout_centerVertical="true"
    android:text="TextView" />

  </RelativeLayout> 

In eclipse layout editor it looks like this (ok): 在eclipse布局编辑器中,它看起来像这样(确定):

在此处输入图片说明

To download image for imageview (@+id/icon) in every row, i use universal image loader library ( https://github.com/nostra13/Android-Universal-Image-Loader ). 要在每一行中为imageview(@ + id / icon)下载图像,我使用通用图像加载器库( https://github.com/nostra13/Android-Universal-Image-Loader )。 The problem is that when image is downloaded, it is smaller as it should be and also the row is smaller. 问题在于,下载图像时,它应该较小,并且行也较小。 If i put the same image as downloaded from resources, everything is good until the download finishes, then image gets smaller and also the row. 如果我放置了与从资源下载的图像相同的图像,则在下载完成之前一切都很好,然后图像变小,并且行也变小了。

Is there anything wrong with my layout? 我的布局有问题吗?

At a glance, I think it is because you have set scaleType to "fitCenter" and defined an absolute value for your layout height. 乍一看,这是因为您已将scaleType设置为“ fitCenter”并为布局高度定义了绝对值。 Your image is getting scaled to fit 120dip minus padding. 您的图片正在缩放以适合120dip减去填充。

<ImageView
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     android:layout_above="@+id/icon"
    android:scaleType="centerInside" />

<TextView
    android:id="@+id/ime"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/icon"
    android:layout_alignParentBottom="true"
    android:layout_marginTop="19dp"
    android:text="TextView" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM