简体   繁体   中英

Android:Invalidating Linear Layout doesn't work

I have an imageView inside of a LinearLayout and when I call invalidate on that LinearLayout it doesnt invalidate until the phone sleeps and wake again.

Is there anyway of forcing the LinearLayout to invalidate straight away?

From android documentation about invalidate function

Invalidate the whole view. If the view is visible, onDraw(android.graphics.Canvas) will be called at some point in the future. This must be called from a UI thread. To call from a non-UI thread, call postInvalidate().

This is over 3 years old, so I'm not anticipating a response, but if you don't think your LinearLayout is invalidating because you're not getting any calls to onDraw() , take a look at https://stackoverflow.com/a/17595671/852795 :

By default all ViewGroup sub-classes do not call their onDraw method, you should enable it by calling setWillNotDraw(false) link

From the doc:

By default, this flag is not set on View, but could be set on some View subclasses such as ViewGroup. Typically, if you override onDraw(android.graphics.Canvas) you should clear this flag.

Try adding setWillNotDraw(false); to your LinearLayout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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