简体   繁体   English

使视图无效的问题

[英]Problems invalidating a View

I have an app with a layout that loads some remote images. 我有一个布局可以加载一些远程图像的应用程序。 When the remote image is being loaded, a clock with 100 forced height is being displayed (i did it overwriting onDraw from imageview), and when the remote image is downloaded and ready to be displayed, the clock dissapears and then the image appears. 加载远程图像时,将显示一个具有100个强制高度的时钟(我将其覆盖了imageview的onDraw),并且当下载远程图像并准备显示该图像时,该时钟消失了,然后出现了图像。

It works, but when the image appears did not receive the correct height, it still haves the height of the clock (100). 它可以工作,但是当图像出现时未收到正确的高度时,它仍然具有时钟的高度(100)。

I dont know why, because when the image is displayed it calls a handler wich refresh the view of the image and the container layout of the image with the new height (365), but it is not working properly. 我不知道为什么,因为当显示图像时,它调用一个处理程序,以新的高度(365)刷新图像的视图和图像的容器布局,但是它不能正常工作。

this is the handler: 这是处理程序:

    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {                
            super.handleMessage(msg);   
            if( ((ImageView)view) != null && resource != null && resource.image != null ){
                ((ImageView)view).setImageBitmap( resource.image );                                 
                view.getLayoutParams().height=height;
                ((ViewGroup)view.getParent()).getLayoutParams().height=height;
                ((ImageView)view).invalidate(); 
                ((ViewGroup)view.getParent()).invalidate();
                ((ViewGroup)view.getParent()).refreshDrawableState();
                view.invalidate();                      
            }
        }           
    };

the handler is being called, the image is being displayed, the height value on the handler is correct (365), but the image is still being displayed with the height of the clock (100). 调用处理程序,显示图像,处理程序上的高度值正确(365),但仍以时钟高度显示图像(100)。

Also i must say that if i block the screen and unblock the screen, the image appears with the correct height (365). 我还必须说,如果我遮挡屏幕并取消遮挡屏幕,则图像显示的高度正确 (365)。 It seems that there is a problem with invalidate(). 看来invalidate()有问题。

Thanks all 谢谢大家

Solved 解决了

I must reinstanciate the view each time i load the image element: 每次加载图像元素时,我都必须重新实例化视图:

view = new FocusableImageView( activity ); view = new FocusableImageView(activity);

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

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