1

I am using a ListView with a WebView every 30 items for special HTML ads (animated) which are provided from a WebServer. This normally works okay. But sometimes it seems to draw the content of the WebView twice as seen in the screenshot below. The WebView continues animating but the misplaced (left bottom) drawing stays the same. When one interacts with the screen (scrolls) the wrongly drawn space disappears.

Screenshot showing the problem

Now my questions are:

  1. Why is this happening?
  2. How can I prevent this from happening?

My current guess for Nr. 1 is: Somehow the WebView gets positioned in the left bottom just for a quick time where it as well draws. Then it gets positioned correctly but the ListView does not redraw that area because it thinks all is still at the same position.

Thanks to anyone who can help.

UPDATE:

I used the same WebView with the animation centered in a RelativeLayout. The same problem occurred there. So the problem is not in the ListView.

Patrick Boos
  • 6,789
  • 3
  • 35
  • 36
  • What is your android device version? Also, you can give it a try to this library : https://github.com/pwnall/chromeview – Lazy Aug 14 '14 at 11:44
  • Show your code. And try to refresh your ListView by calling `listView.invalidateViews()` or `adapter.notifyDataSetChanged()`. – Manuel Allenspach Aug 14 '14 at 13:52
  • I have not tested it on all versions. But it happens on 4.2 and 4.4. Sadly I can not switch the ChromeView because the WebView is made through a library. Because it is a library, I as well can not share the source code in there. – Patrick Boos Aug 15 '14 at 07:24
  • @Manu notifyDataSetChanged() is called at the right time. Just calling it again would not help. And invalidateViews would probably work, but it would need to be at the right time. Question is: When is the right time. Calling it every second or so is not okay. – Patrick Boos Aug 15 '14 at 07:25
  • @PatrickBoos what can you share? Perhaps at least the `ListView` code, where you use the `WebViews`. – Simas Aug 15 '14 at 08:21
  • @user3249477 Just wrote an update now. I tried to use the same WebView outside of the ListView and it produces the same problem. So the issue is not in the ListView. – Patrick Boos Aug 15 '14 at 09:13
  • 1
    @PatrickBoos You should have started your question with this statement: *The problem is in the code which I cannot show you*. – Simas Aug 15 '14 at 09:21
  • @user3249477 I am working on some sample code that reproduces the problem. Some code I can share. But I think it is a general problem. With animations and the WebView. So I was thinking that maybe someone else experienced this already. – Patrick Boos Aug 15 '14 at 09:24
  • Please post your layout xml file and your listview adapter class here – Sadegh Aug 20 '14 at 07:19
  • Run Hierarchy Viewer http://developer.android.com/tools/debugging/debugging-ui.html to see what is going on. I would start with this tool instead guessing. – Damian Petla Aug 20 '14 at 18:36
  • a possible related issue: https://code.google.com/p/android/issues/detail?id=20051 – hrishitiwari Aug 20 '14 at 19:39
  • @Loop already did. But it does not show any other view. That second drawing does not show up in hierarchyviewer. – Patrick Boos Aug 21 '14 at 05:33

2 Answers2

0

WebViews don't go well with ListViews, you may have to do a lot of hacks, including handling touch events, etc.

If you list doesn't display an 'infinite' list of items, or at least the list is never too big, you can maybe give a try on this custom listview from this other post: https://stackoverflow.com/a/21878703/684582

it was designed to support a ListView inside a ScrollView, but it might just help you on your problem without much redesign. I hope it helps! Good luck!

Community
  • 1
  • 1
Alécio Carvalho
  • 13,481
  • 5
  • 68
  • 74
  • Thank you. I just tried it outside a ListView and it has the same problem. So the problem is not ListView related. But thank you anyway! – Patrick Boos Aug 15 '14 at 09:14
0

I found the problem in the WebView coming from the advertiser. The problem seems to be setting the LayerType to HARDWARE. That caused the Problem. Setting the the LayerType to NONE or SOFTWARE the problem went away. Now I just wonder WHY that caused the problem.

A normal WebView uses LAYER_TYPE_NONE by default.

Solution in short:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
Patrick Boos
  • 6,789
  • 3
  • 35
  • 36