gpt4 book ai didi

android - picasso 无法在@override 上加载动画

转载 作者:行者123 更新时间:2023-11-30 01:55:51 24 4
gpt4 key购买 nike

好的,我已经覆盖了 Picassos 方法,我的逻辑如下。在适配器中,我有一个布局,我的图像将被下载,但在此之前,我在整个屏幕上有一个 FrameLayout 来存储我的动画可绘制对象。接下来是我的代码:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

final holder mHolder;


if (convertView == null) {
mHolder = new holder();


convertView = mInflater.inflate(R.layout.adapter_prodavci, parent, false);
mHolder.slika = (ImageView) convertView.findViewById(R.id.ImageViewProdavciMain);
mHolder.loading = (ImageView) convertView.findViewById(R.id.loadingImageAdapterProdavci);
mHolder.frame = (FrameLayout) convertView.findViewById(R.id.frameAdapterProdavci);
convertView.setTag(mHolder);
} else {
mHolder = (holder) convertView.getTag();
}
final Animation myAnim = AnimationUtils.loadAnimation(mContext.getApplicationContext(), R.anim.rotator);
Prodavci prodavci = getItem(position);
Picasso.with(mContext)
.load(prodavci.getSlika())
.into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
// myAnim.cancel();
// myAnim.reset();
mHolder.loading.clearAnimation();
mHolder.loading.setVisibility(View.GONE);
mHolder.loading.invalidate();
mHolder.frame.setVisibility(View.GONE);
mHolder.frame.invalidate();
mHolder.slika.setVisibility(View.VISIBLE);
mHolder.slika.setImageBitmap(bitmap);
mHolder.slika.bringToFront();
mHolder.slika.invalidate();
}

@Override
public void onBitmapFailed(Drawable errorDrawable) {

}

@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
mHolder.loading.startAnimation(myAnim);
}
});

return convertView;
}

和我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_margin="11.333dp"
android:layout_marginLeft="11.33dp"
android:layout_marginRight="11.33dp"
android:layout_marginTop="11.33dp"
android:background="@drawable/okvirlogo">


<aik.akcijeikatalozi.objetki.SquareImageView
android:id="@+id/ImageViewProdavciMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="3dp"
android:background="@android:color/transparent"
android:scaleType="center" />


</LinearLayout>


<FrameLayout
android:id="@+id/frameAdapterProdavci"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#ffffff">


<ImageView
android:id="@+id/loadingImageAdapterProdavci"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal|center_vertical"
android:background="@android:color/transparent"
android:src="@drawable/loadingwheels" />


</FrameLayout>

</RelativeLayout>

问题是在方法 onBitmapLoaded 之后动画没有被隐藏,当我向下滚动 gridView 并将其拉回来时它被隐藏,然后它就消失了。有什么建议吗?

最佳答案

错误的逻辑。这是代码:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

final holder mHolder;


if (convertView == null) {
mHolder = new holder();


convertView = mInflater.inflate(R.layout.adapter_prodavci, parent, false);
mHolder.slika = (ImageView) convertView.findViewById(R.id.ImageViewProdavciMain);
convertView.setTag(mHolder);
} else {
mHolder = (holder) convertView.getTag();
}

Prodavci prodavci = getItem(position);



Picasso.with(mContext)
.load(prodavci.getSlika())
.into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
mHolder.slika.clearAnimation();
mHolder.slika.setImageBitmap(bitmap);
}

@Override
public void onBitmapFailed(Drawable errorDrawable) {

}

@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
Animation myAnim = AnimationUtils.loadAnimation(mContext.getApplicationContext(), R.anim.rotator);
placeHolderDrawable = mContext.getResources().getDrawable(R.drawable.loadingwheels);
mHolder.slika.setImageDrawable(placeHolderDrawable);
mHolder.slika.startAnimation(myAnim);
}
});

return convertView;
}

XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_margin="11.333dp"
android:layout_marginLeft="11.33dp"
android:layout_marginRight="11.33dp"
android:layout_marginTop="11.33dp"
android:background="@drawable/okvirlogo">


<aik.akcijeikatalozi.objetki.SquareImageView
android:id="@+id/ImageViewProdavciMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="11.333dp"
android:layout_marginLeft="11.33dp"
android:layout_marginRight="11.33dp"
android:layout_marginTop="11.33dp"
android:background="@android:color/transparent" />


</LinearLayout>


</RelativeLayout>

关于android - picasso 无法在@override 上加载动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32253654/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com