Java 在listview中使用Fit_XY

Java 在listview中使用Fit_XY,java,android,android-listview,Java,Android,Android Listview,这是我的自定义ListViewAdapter中保存imageview的一行代码。我需要将我放入的图像缩小到列表视图中图像视图的大小 我想应用imageview.setImageResource(custom.getcustomImage())指向适配器中的项目,但我得到一个错误 holder.item3.setImageResource(custom.getcustomImage()); 我的代码是这样的 Cannot invoke setScaleType(ImageView.ScaleTy

这是我的自定义
ListViewAdapter
中保存imageview的一行代码。我需要将我放入的图像缩小到
列表视图中
图像视图的大小

我想应用
imageview.setImageResource(custom.getcustomImage())指向适配器中的项目,但我得到一个错误

holder.item3.setImageResource(custom.getcustomImage());
我的代码是这样的

Cannot invoke setScaleType(ImageView.ScaleType) on the primitive type int
我该如何使用此
FIT_XY
,是否有其他方法可以在我的
列表视图中的
ImageView
中安装图像

我的适配器

holder.item3.setImageResource(custom.getcustomImage().setScaleType(ScaleType.FIT_XY);
行布局

a = new Custom("String one","Stringtwo", R.drawable.image);

我看到
项目3
是一个
图像视图
。您正试图将图像应用于该
ImageView

在这里,您的
getcustomImage()
可能会返回imageResId

如果getcustomImage()方法返回图像分辨率id(为整数值),请使用

将图像应用于
ImageView

最后,在
ImageView

holder.item3.setImageResource(custom.getcustomImage());
阅读更多关于和

编辑: 不久
改变这一点

holder.item3.setScaleType(ScaleType.FIT_XY);
为此:

holder.item3.setImageResource(custom.getcustomImage().setScaleType(ScaleType.FIT_XY);
编辑:
rowlayout.xml
中对
ImageView
说wrap_内容,您就消除了
scaleType
选项,因为
ImageView
将根据图像大小调整自身大小。您可能希望提供一个静态宽度,以便在列表中获得更好的视觉效果(所有图像的宽度将相等)。你想要FITXY,但是考虑使用CIMTIN作为一种选择(更好的观点)。并尝试在rowlayout中使用scaleOption,以便在图形布局中查看其输出

holder.item3.setImageResource(custom.getcustomImage());
holder.item3.setScaleType(ScaleType.FIT_XY);


我没有收到错误,但我的图像不适合图像视图大小。我将发布我的适配器和我正在调用的代码,我将看到您的编辑。请分享您的行布局。问题应该在那里。谢谢您的帮助。我给我的imageviews一个固定的值50dp,我的图像正在重新调整大小。感谢您提供其他选项类型。我试过fitCenter,但fitXY对我来说效果很好。
holder.item3.setImageResource(custom.getcustomImage().setScaleType(ScaleType.FIT_XY);
holder.item3.setImageResource(custom.getcustomImage());
holder.item3.setScaleType(ScaleType.FIT_XY);
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:background="#FFFFFF"
    android:padding="6dip" >

    <!-- android:background="@color/Cream" -->

    <ImageView
        android:id="@+id/icon"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="6dip"
        android:contentDescription="TODO"
        android:src="@drawable/launchicon" 
        android:scaleType="fitXY"/>

    <TextView
        android:id="@+id/firstLine"
        android:layout_width="wrap_content"
        android:layout_height="26dip"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@id/icon"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:text="Example application"
        android:textColor="#000000"
        android:textSize="12sp" />

    <TextView
        android:id="@+id/secondLine"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/firstLine"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_alignWithParentIfMissing="true"
        android:layout_toRightOf="@id/icon"
        android:gravity="center_vertical"
        android:text="Description"
        android:textColor="#000000"
        android:textSize="16sp" />

</RelativeLayout>