簡體   English   中英

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

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

當項目具有不同高度的圖像時,如何使列表視圖順利運行? 當我上列表時,使用回收並計算 getView 中的 ImageView 維度,這會令人毛骨悚然並跳過部分 謝謝

如果您當時對 ImageView 使用具有固定項目高度的自定義 Listview,則需要使用:

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

使用任何大小的圖像都可以適合 listView 項目大小

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

圖像將被修復

不要更改getView()方法上的視圖大小。 而是覆蓋 Adapter 方法getViewTypeCount()getItemViewType()

如果您正確使用這些方法,為不同大小的視圖返回不同的數字,Android 將在getView()上為您回收正確的視圖。 這樣,列表的測量是正確的,列表將平滑滾動。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM