I have a custom view group that I'm animating around on a screen based on touch events (drag and drop, for instance).
I want it to be able to draw slightly outside its bounds, and still animate smoothly.
I tried setting setLayerType(LAYER_TYPE_HARDWARE, null) on the dragging view, and performance was great, but anything outside the bounds was clipped.
I tried setting LAYER_TYPE_NONE, performance was still fine, but there was animation ghosting/streaking where the view had been dragged (as if it were smearing the screen).
Tried this on a Moto X and Nexus 4, same results.
What's the best way to approach this? Is setClipChildren(false) supposed to work with LAYER_TYPE_HARDWARE? Interestingly, LAYER_TYPE_SOFTWARE exhibits the same unexpected clipping as does LAYER_TYPE_HARDWARE.
Try to use following combination:
setClipChildren(false);
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
android:hardwareAccelerated="false"
As described here: ViewPager and setClipChildren(false) workaround for 2.x devices
I had a similar problem when doing exactly the same thing. I wanted a drop shadow beneath my views. The problem is that the system will only clean up the rectangle left by the view you have moved and since you are rendering outside that view by choosing to not clip children, the rectangle is not covering all of your tracks and remains of the rendered view leave a smudgy sort of mess behind.
The solution I used was to put the view I wanted to move inside another view (A RelativeLayout with the child view aligned to the parent's center) that is slightly larger and does cover the drop shadow or whatever else you are rendering outside the bounds of your child. You can set the background of that parent view to transparent/clear. Now attach the drag action to your parent view and the Rect that is cleaned up behind it will also clean up the child's mess.
The only other way I found to do it which was very costly in terms of performance was to re-render the views that show the mess at each frame. I couldn't find any other solutions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With