requestlayout doing nothing in 4.4.3 - android

We have an app that's rather complex with a fairly deep view hierarchy. It works fine on every device between 4.x and 4.4.2, however in 4.4.3 weird stuff starts happening. Sometimes (read most of the time) when we show a page with a horizontal scrollview and a viewpager we can't scroll the horizontal scrollview and the viewpager doesn't measure new views. I've chased the bug down and the horizontal scrollview seems to scroll fine, but the call we do to requestLayout sees that isLayoutRequested on getParent is already true, and stops doing anything (and therefor doesn't redraw).
When this happens I've set a breakpoint on the base "View" class onLayout function. The debugger does stop there when I draw up the initial layout, but when I end up in a state where it's broken triggering requestLayout never triggers a onLayout in ANY view.
In what scenarios can you call requestLayout on a view and never have a debugger trigger on View.OnLayout? How can I debug this without having the 4.4.3 sources so I can see whats going on deeper in the stack?

Related

Android View bizarre behaviour

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?
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().

android layoutview item in listview

I have faced with very strange behavior in listview android.
I puts several ViewGroups(actually RelativeLayout) into a ListView as
its item. The ViewGroup has TextViews and ImageViews.
I registered OnClickListener on the ImageViews in the ViewGroup.
When I tabbed the ImageViews, The OnClickListener is called in delayed
(It was over than 2 seconds.). Sometimes, the OnClickListener is
never called unless I tabbed another view in a device.
In that case, the method is called multiply and in burst.
I think it seems to be related to focus. But I can not find a solution.
This strange behavior occurs in only Galaxy S3. It works fine in Galaxy S4.
Meanwhile, OnTouchListener works fine even in the case in Galaxy S3.
It means that a touch event arrives the View in the ViewGroup. I can not
understand why the OnClickListener is called delayed or in out of focus
even it receives touch events in OnTouchListeners.
12-27 23:31:51.203: I/debug(19534): myimageview touch event!!!
12-27 23:31:51.268: I/debug(19534): myimageview touch event!!!
12-27 23:31:51.278: I/debug(19534): myimageview touch event!!!
12-27 23:31:51.278: I/debug(19534): myimageview touch event!!!
12-27 23:31:53.333: D/AbsListView(19534): unregisterIRListener() is called
12-27 23:31:53.433: D/AbsListView(19534): unregisterIRListener() is called
12-27 23:31:53.518: I/debug(19534): dofollow clicked!!!222222222222
In above log, you can see 4 times touch event. But OnClickListener is
call after 2 seconds from last touch event.
UPDATE:
I did reset my device(GalaxyS3) by tabbing reset button which is shown when
I pressed long a power button of my device. And I tested it again. But,
It was same result.
However, Today, I powered off my device by seperation of a battery.
And powered on. It works fine without any source code changes!.
Is there any difference between the reset by power-off and software-reset?
Anyway, It words good this time. I will report it again if the
behavior occurs again next time.
UPDATE:
I figure out that this issue is happened in all android devices. I guess
that it is related to drawing cache of ListView. I guess that ListView
makes drawing caches for its child views in sometimes. I checked it out
by enabling showing boundaries of all views in android system setting.
After enabling showing boundaries, I navigates several items in ListView.
Then, I saw some view of child of ListView does not have its child
layout boundary. It means that it is just image not a view.
In that time, All controls(including ImageView) does not work.
After just little scrolling of the ListView, The queued click events are
flushed to a child control at that time. It means that scrolling of ListView
triggers changing of the cache image with the real view.
I can not find a way turning off this drawing cache in ListView.
UPDATE:
I solved this issue. I feeds views created statically by myself instead of
using convertView in getView method. In this case, something wrong is
happend inside of ListView. I changed it to use convertView always.

OnDraw bug in android 4.2

I have downloaded the 4.2 image for tests and I'm surprised with one thing. I have a HorizontalScrollView filled by ImageView's ancestors in my application. I rely on the fact, that onDraw in these ImageViews is called only when the view becomes explicitly visible to a user. But what I'm observing in 4.2 is that onDraw is called just at the moment of adding views to the HorizontalScrollView. Is it a supposed behaviour? Or am I missing anything?
Thanks for help.
Generally onDraw is called when the view has been inflated and after its measured.
I would never assume that onDraw means that that view is visible to a user. Even the onDisplayHint is not assurance that the view is visible.
Also worth noting the onDraw can be called multiple times, as other views move or the View hierarchy is invalidated().
Hope that helps?
If not have a good read through - Custom Views

Why is ScrollView sometimes (!) not scrolling when scrollTo is called (in an onClick event)

So I have this button (ImageView with onClick method) on the right side of the screen which when I pull it to the left extends into a SeekBar where you can select the time of day. To create this I have made a ScrollView with a horizontal LinearLayout with a see through view on the left and the "button"+SeekBar on the right (mostly outside of the screen). The "button" has an OnTouch and OnClick listener.
In the onTouch the scrollview is told to smoothScrollTo the correct location depending on where the finger is moving. When you move less than a certain threshold and release the onClick is called.
In the onClick I have told the scrollview to smoothScrollTo / scrollTo / fullScroll. The fullScroll didn't ever work. The smoothScrollTo works most of the time on one device (HTC Desire with Android 2.2.2) but never worked IN THE ONCLICK (?) on another device (Samsung Galaxy Tab (the old one) with Android 2.2). The scrollTo sometimes works on both devices... I am sure the onClick is called as I log that when it starts and also directly after telling the ScrollView to scroll.
I have tried posting the scrollTo to the ScrollView in a runnable and a delayed runnable:
scrollView.postDelayed(new Runnable() {
#Override
public void run() {
scrollView.scrollTo(left, 0);
Log.d("SomeTag", "The scroller should scroll to: "+left);
}
}, 200);
But this worked just as often (so sometimes) as not posting it...
I am nonplussed. I am used to working with Android and used to different devices behaving differently, but I am not used to having the same call on the same device "sometimes" working and "sometimes" not... Any help would be greatly appreciated!
See this answer.
ScrollView.scrollTo() may not working if some layout changes are being made when you called the method. And you are right, using postDelayed() you cannot guarantee that layout changes in will always finish within the same delay time.

Android custom view is not drawn properly

I have a custom widget based on the Android Gallery view. It is slightly customized to show the elements from the left of the view without a gap and pass required events to my listener.
On the very first view layout everything works perfect. However when I pause and resume the activity the view freezes. It is visible, I can see OnTouch() event handlers working, view positions adjusted, but the picture is not changing. The OnDraw() method for the Gallery widget is not called at all!
I have another widget in this layout (a sliding drawer) and as soon as I barely move the drawer everything starts working back again as it should.
I am completely out of ideas how to fix this. Tried different ways to force the OnDraw() method but it is just not working.
Any ideas?
Thanks
Make sure you override onDraw(android.graphics.Canvas) and not OnDraw() (both the Canvas argument and the lower case initial 'o').
If it's not that, then please post some code to look at it.

Categories

Resources