0

I have this bizarre behaviour when calling invalidate. I have made a custom viewgroup containing a bunch of imageviews.

I set up a onTouch listener with the on touch method to scroll the view. I know all the code is correct in terms of distances to scroll etc. by using logcat.

Now, for some reason the onLayout method is not being called after I call this.invalidate(). When I try to scroll, nothing changes on the screen. However, after I pause the activity and resume it, the screen will have shifted by the amount I scrolled.

I am not blocking the UI thread because there is nothing to block it with. In any case, I have tried postInvalidate() and nothing has worked.

Anybody have any bloody idea what's going on?

asked Apr 19, 2015 at 14:25
1
  • invalidate() just redraws the View. It doesn't relayout anything. You need to call requestLayout() to start a new layouting process. Commented Apr 19, 2015 at 14:57

1 Answer 1

1

invalidate() does not relayout the view, it only causes the view to be redrawn. If you want to relayout it (which will invoke onLayout()) you also have to make a call to requestLayout().

answered Apr 19, 2015 at 14:54
Sign up to request clarification or add additional context in comments.

3 Comments

I see! How did you come across that information? So invalidate calls onDraw()?
Also, do you have any idea how scrollview makes the view scroll smoothly? At the moment, it seems like I need to wait for the MotionEvent.ACTION_UP before it calls onLayout. Am I blocking the UI thread somehow?
You can find more information in the documentation of these methods. A ScrollView does not re-layout its content, it's rather complicated. You could have a look into the ScrollView source code: grepcode.com/file/repository.grepcode.com/java/ext/…

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.