Android的,setVisbility里去了不工作的RelativeLayout的去了、工作、Android、setVisbility

2023-09-06 03:06:03 作者:你最近还好么〃

我使用的是RelativeLayout的把一个旋转微调动画上一个占位符图像的顶部而真正的图像被加载在后台线程。

当真正的位图是准备好了,code以下运行在UI线程与Activity.runOnUiThread(Runnable接口)

现在的问题是,我所有的企图隐藏旋转图像后加载的实像忽视了。我得到它的工作终于通过将潜在的ImageView到前面,但我只是好奇setVisibility(View.GONE)和其他方法我试过不工作的原因。我尝试了各种方法试图隐藏旋转动画,但他们都不工作。

在微调图像简单地宣布在ImageView的是:

 机器人:SRC =@可绘制/ spinner_black_20
 

然后,我开始了旋转动画就可以了。一旦真实的图像加载,这就是我试图掩盖它(在UI线程如上所述)

 视图V =(查看)imageView.getParent();
ImageView的微调=(ImageView的)v.findViewById(R.id.loading_spinner);
如果(微调!= NULL){
    spinner.getAnimation()取消()。 //这个作品中,动画停止
    spinner.setVisibility(View.INVISIBLE); //不能正常工作,微调的位图仍然存在
    spinner.setVisibility(View.GONE); //不起作用
    spinner.getDrawable()的setVisible(假的,假的)。 //试过,没有快乐
    spinner.refreshDrawableState(); //认为这可能帮助,没了
    spinner.invalidate(); //也不是这个
    imageView.bringToFront(); //这个工程,在微调消失背景
}
imageView.setImageBitmap(位);
 
中文新课程 协助教育工作者教授 Android 应用开发

解决方案

尝试调用 spinner.clearAnimation(); 前setVisibility

这是丰富的暗示......

I am using a RelativeLayout to put a rotating spinner animation on top of a placeholder image while the real image is being loaded in a background thread.

When the real bitmap is ready, the code below is run with in the UI thread with Activity.runOnUiThread(Runnable)

The problem is, that all my attempts to hide the rotating image after the real image was loaded seem to fail. I got it working finally by bringing the underlying imageview to the front, but I'm just curious why setVisibility(View.GONE) and the other methods I tried are not working. I tried various methods trying to hide the rotating animation, but none of them worked.

The spinner image is declared simply in an ImageView as:

android:src="@drawable/spinner_black_20"

Then I start an rotation animation on it. Once the real image is loaded, this is where I try to hide it (in the UI thread as mentioned above)

View v = (View)imageView.getParent();
ImageView spinner = (ImageView) v.findViewById(R.id.loading_spinner);
if (spinner != null) {
    spinner.getAnimation().cancel(); // this works, the animation stops
    spinner.setVisibility(View.INVISIBLE); // doesn't work, spinner bitmap still there
    spinner.setVisibility(View.GONE); // doesn't work
    spinner.getDrawable().setVisible(false, false); // tried this, no joy
    spinner.refreshDrawableState(); // thought this might help, nope
    spinner.invalidate(); // nor this
    imageView.bringToFront(); // this works, in that spinner disappears to background
}
imageView.setImageBitmap(bitmap);

解决方案

Try calling spinner.clearAnimation(); before the setVisibility.

Which is what Rich alluded to...