简体   繁体   English

Android - 项目中具有不同大小图像的 ListView 使 ListView 混蛋

[英]Android - ListView with different sizes images in items makes the ListView jerk

How do I make listview run smoothly when the items have images with various heights?当项目具有不同高度的图像时,如何使列表视图顺利运行? Using recycling and calculating the ImageView dimension in the getView when I go up the list jerks horribly and skips parts Thank you当我上列表时,使用回收并计算 getView 中的 ImageView 维度,这会令人毛骨悚然并跳过部分 谢谢

If you are using Custom Listview With fixed item Height at that time for ImageView you need to use :如果您当时对 ImageView 使用具有固定项目高度的自定义 Listview,则需要使用:

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:src="@drawable/ic_launcher" >

Using this Image which is any size can be Fit to listView Item size使用任何大小的图像都可以适合 listView 项目大小

android:adjustViewBounds="true"
android:scaleType="fitXY" 

Image Will be Fixed图像将被修复

Don't change the view size on the getView() method.不要更改getView()方法上的视图大小。 Instead override the Adapter methods getViewTypeCount() and getItemViewType() .而是覆盖 Adapter 方法getViewTypeCount()getItemViewType()

If you use these methods right, returning a different number for different size views, Android will recycle the right view for you on getView() .如果您正确使用这些方法,为不同大小的视图返回不同的数字,Android 将在getView()上为您回收正确的视图。 This way the list is measured correct and the list will scroll smoothly.这样,列表的测量是正确的,列表将平滑滚动。

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

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