使用 AQuery 快速滚动时,ImageView 在 ListView 中的错误位置可见
ImageView visible in ListView on wrong position when scrolling fast, using AQuery
我在 listView 的适配器中得到了以下 getView:
@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
View view = convertView;
if (view == null) {
view = LayoutInflater.from(context).inflate(R.layout.item_message, null);
}
final Message msg = getItem(position);
final AQuery aq = new AQuery(view);
aq.id(R.id.message_baloon).background(myMessage ? R.drawable.chat_message_own : R.drawable.chat_message_other);
// shared image
if (msg.getPhotos() != null && msg.getPhotos().size() != 0) {
aq.id(R.id.sent_photo).visible();
aq.image(msg.getPhotos().get(0).getUrl(), true, true, 540, R.drawable.room_details_gallery_placeholder);
aq.clicked(new View.OnClickListener() {
@Override
public void onClick(View v) {
//show fullsecreen photo
}
});
} else {
aq.id(R.id.sent_photo).gone();
}
if (msg.getText() == null || msg.getText().length() == 0) {
aq.id(R.id.message).gone();
} else {
aq.id(R.id.message).text(msg.getText());
aq.id(R.id.message).visible();
}
return view;
}
该方法实际上更长,但这部分包含与该 ImageView 相关的所有内容。因此,正如标题所述,当 ImageView 非常快速地滚动时,"R.id.sent_photo",对于没有照片的位置是可见的,而不是几分之一秒,它仍然可见(这是 AndroidQuery 库我正在使用)。
谢谢!
我遇到了同样的问题,所以,我在我的自定义适配器中使用了以下方法,我得到了解决方案。
在您的 ListViewItemsAdapter 中添加以下方法:
@Override
public int getCount() {
return alUpgradeTour.size();
}
@Override
public int getItemViewType(int position) {
return position;
}
@Override
public int getViewTypeCount() {
return getCount();
}
试试吧,你也会有解决办法的。
试试这个,AndroidQuery 库似乎没有在下载前放置占位符图像
if (msg.getPhotos() != null && msg.getPhotos().size() != 0) {
aq.id(R.id.sent_photo).visible();
aq.id(R.id.sent_photo).setImageResource(R.drawable.room_details_gallery_placeholder);
aq.image(msg.getPhotos().get(0).getUrl(), true, true, 540, R.drawable.room_details_gallery_placeholder);
aq.clicked(new View.OnClickListener() {
@Override
public void onClick(View v) {
//show fullsecreen photo
}
});
} else {
aq.id(R.id.sent_photo).gone();
}
解决方案是不使用内存缓存:
aq.image(msg.getPhotos().get(0).getUrl(), false, true, 540, R.drawable.room_details_gallery_placeholder);
AndroidQuery 在该图像函数的某处执行以下操作
public static void async(Activity act, Context context, ImageView iv, String url, boolean memCache, boolean fileCache, int targetWidth, int fallbackId, Bitmap preset, int animation, float ratio, float anchor, Object progress, AccountHandle ah, int policy, int round, HttpHost proxy, String networkUrl){
Bitmap bm = null;
if(memCache){
bm = memGet(url, targetWidth, round);
}
if(bm != null){
iv.setTag(AQuery.TAG_URL, url);
Common.showProgress(progress, url, false);
setBmAnimate(iv, bm, preset, fallbackId, animation, ratio, anchor, AjaxStatus.MEMORY);
}else{
Bit...
因此,如果它从 memCache 获得位图,它会调用 setBmAnimate
private static void setBmAnimate(ImageView iv, Bitmap bm, Bitmap preset, int fallback, int animation, float ratio, float anchor, int source){
bm = filter(iv, bm, fallback);...
过滤器是:
private static Bitmap filter(View iv, Bitmap bm, int fallback){
//ignore 1x1 pixels
if(bm != null && bm.getWidth() == 1 && bm.getHeight() == 1 && bm != empty){
bm = null;
}
if(bm != null){
iv.setVisibility(View.VISIBLE);
}else if(fallback == AQuery.GONE){
iv.setVisibility(View.GONE);
}else if(fallback == AQuery.INVISIBLE){
iv.setVisibility(View.INVISIBLE);
}
return bm;
我在 listView 的适配器中得到了以下 getView:
@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
View view = convertView;
if (view == null) {
view = LayoutInflater.from(context).inflate(R.layout.item_message, null);
}
final Message msg = getItem(position);
final AQuery aq = new AQuery(view);
aq.id(R.id.message_baloon).background(myMessage ? R.drawable.chat_message_own : R.drawable.chat_message_other);
// shared image
if (msg.getPhotos() != null && msg.getPhotos().size() != 0) {
aq.id(R.id.sent_photo).visible();
aq.image(msg.getPhotos().get(0).getUrl(), true, true, 540, R.drawable.room_details_gallery_placeholder);
aq.clicked(new View.OnClickListener() {
@Override
public void onClick(View v) {
//show fullsecreen photo
}
});
} else {
aq.id(R.id.sent_photo).gone();
}
if (msg.getText() == null || msg.getText().length() == 0) {
aq.id(R.id.message).gone();
} else {
aq.id(R.id.message).text(msg.getText());
aq.id(R.id.message).visible();
}
return view;
}
该方法实际上更长,但这部分包含与该 ImageView 相关的所有内容。因此,正如标题所述,当 ImageView 非常快速地滚动时,"R.id.sent_photo",对于没有照片的位置是可见的,而不是几分之一秒,它仍然可见(这是 AndroidQuery 库我正在使用)。
谢谢!
我遇到了同样的问题,所以,我在我的自定义适配器中使用了以下方法,我得到了解决方案。
在您的 ListViewItemsAdapter 中添加以下方法:
@Override
public int getCount() {
return alUpgradeTour.size();
}
@Override
public int getItemViewType(int position) {
return position;
}
@Override
public int getViewTypeCount() {
return getCount();
}
试试吧,你也会有解决办法的。
试试这个,AndroidQuery 库似乎没有在下载前放置占位符图像
if (msg.getPhotos() != null && msg.getPhotos().size() != 0) {
aq.id(R.id.sent_photo).visible();
aq.id(R.id.sent_photo).setImageResource(R.drawable.room_details_gallery_placeholder);
aq.image(msg.getPhotos().get(0).getUrl(), true, true, 540, R.drawable.room_details_gallery_placeholder);
aq.clicked(new View.OnClickListener() {
@Override
public void onClick(View v) {
//show fullsecreen photo
}
});
} else {
aq.id(R.id.sent_photo).gone();
}
解决方案是不使用内存缓存: aq.image(msg.getPhotos().get(0).getUrl(), false, true, 540, R.drawable.room_details_gallery_placeholder);
AndroidQuery 在该图像函数的某处执行以下操作
public static void async(Activity act, Context context, ImageView iv, String url, boolean memCache, boolean fileCache, int targetWidth, int fallbackId, Bitmap preset, int animation, float ratio, float anchor, Object progress, AccountHandle ah, int policy, int round, HttpHost proxy, String networkUrl){
Bitmap bm = null;
if(memCache){
bm = memGet(url, targetWidth, round);
}
if(bm != null){
iv.setTag(AQuery.TAG_URL, url);
Common.showProgress(progress, url, false);
setBmAnimate(iv, bm, preset, fallbackId, animation, ratio, anchor, AjaxStatus.MEMORY);
}else{
Bit...
因此,如果它从 memCache 获得位图,它会调用 setBmAnimate
private static void setBmAnimate(ImageView iv, Bitmap bm, Bitmap preset, int fallback, int animation, float ratio, float anchor, int source){
bm = filter(iv, bm, fallback);...
过滤器是:
private static Bitmap filter(View iv, Bitmap bm, int fallback){
//ignore 1x1 pixels
if(bm != null && bm.getWidth() == 1 && bm.getHeight() == 1 && bm != empty){
bm = null;
}
if(bm != null){
iv.setVisibility(View.VISIBLE);
}else if(fallback == AQuery.GONE){
iv.setVisibility(View.GONE);
}else if(fallback == AQuery.INVISIBLE){
iv.setVisibility(View.INVISIBLE);
}
return bm;