Android - view disappear during animation - android

I got custom animation, create on runtime just to simple translate.
Everything is working fine, got no problems with it, but on
Nexus 10 with latest android animation randomly start disappear and
than I can't do anything but restart the app.
Everything is working, I can see the view on the first and last frame of the animation, the issue is just during the animation, like it won't render it.
When I highlight all the nested layouts I can see that animation occur.
The app is complex, cause I got Unity player as subview and also video view in there.
Any ideas?

In the end it was "GONE" parameter on one of the views which was causing that issue. I replace it with "INVISIBLE" and this fix it.

Related

MotionLayout breaks the redrawing of (nested) subviews

I'm having problems with views not refreshing in MotionLayout.
Seems like at some point the refresh/redraw mechanism of MotionLayout becomes broken and the subviews (including the nested ones) are having random problems updating themselves on the screen. What I have experienced so far:
RecyclerView is not refreshed sometimes. This happens when new data is available, I'm using Paging library to fill the data. I have fixed it with a workaround of scrolling 1 pixel when I got new data there - recyclerView.smoothScrollBy(0,1). After that the RecyclerView starts redrawing itself just fine.
When the keyboard is opened it randomly messes the nested subview redrawing. There is an issue in github โ here where a guy reproduces all this by adding an EditText to official MotionLayout examples. Some examples of the problems that I'm seeing:
I'm using TextInputLayout with app:endIconMode="clear_text" in MotionLayout -> ConstraintLayout -> TextInputLayout and the X button is sometimes not shown when I start typing (also after closing the keyboard).
TextView is redrawn partially! I'm showing "No Results" or "No Posts" text in a TextView, switching between them based on some logic, but instead of refreshing the whole text only "No" is shown in the UI. I have debugged it, Layout Inspector says everything is fine, the text view value is "No Results", but I don't see it on the screen.
Some other animations are broken, like indeterminate progress animation of nested SwipeRefreshLayout
IMPORTANT: All the refresh/redraw issues are fixed when I do a transition! When I come to some messed state where 3 nested subviews are frozen/partially drawn, then I just need to press a button that triggers my transition, and all of them are happily redrawing themselves!
Please let me know if this is a known problem and if there is a workaround for this. I could do invisible 1 pixel transition maybe, but I cannot even detect when the MotionLayout refreshing becomes broken, handling keyboard and new data of RecyclerView doesn't seem to cover all the cases. Otherwise, I will have to move back to ConstraintLayout and think on implementing the amazing OnSwipe functionality myself (if that is even possible in ConstraintLayout).
I am also experiencing issues with update of nested subviews and MotionLayout. Google please fix this issue with MotionLayout.
Using requestLayout() on the nested subviews will often update the Views.
By default during transition motionLayout does not honor requestlayout() during transitions.
Add layoutDuringTransition=honorRequest during the transition
<Transition ... motion:layoutDuringTransition="honorRequest" ... \>
Not really an answer, but too long for a comment:
Since you are facing multiple problem with possibly multiple root causes, I would suggest to create a Sandbox project and reproduce each problem at a time in a safe and simple environment.
To me it seem like you have one problem with the paging lib (not with motionLayout in this case) and another problem with the EditText.
You should check your paging code without ML and check your EditText problem without any scrolling views. I know this is not much of a help, but maybe a guide how to tackle these problems. Mind that MotionLayout is still in beta and especially release 2.0.0-beta02 and beta03 was pretty messy with regression errors. Update to the newest version (beta04 as of now) or continue using a stable version.
Sometimes it also helps to search the official tickets for MotionLayout

Shared element transition not showing on top

I'm trying to run a shared element transition from a recycler view to a detail view containing a pager. Pretty much the same as in this blog post.
Everything works, except that the back-from-detail-to-overview animation is clipped to the overview recycler view cells.
After watching this talk, I learned, that unless setSharedElementsUseOverlay is set to false on the activity's window, the transitions will run on an overlay that's on top of everything - the whole content of the activity if I understood correctly. So it should not be possible that the transition is hidden or clipped.
I searched both for setSharedElementsUseOverlay and windowSharedElementsUseOverlay in my project and didn't find anything. The default is supposed to be true. I also tried setting it explicitly to true, both in the theme and programmatically and nothing... the transition is still clipped!
I tried to cause the clipping with the demo project from the blog post, and also wasn't able to - setting setSharedElementsUseOverlay to false doesn't cause any clipping. I ensured that no view in the whole project has clipChildren or clipPadding set to false.
I have no idea what else to do. I tried debugging Android's sources but the transitions classes are unwieldy and I couldn't even find where the overlay view is used. The only thing that I get working in my project is setting clipChildren and clipPadding to false all the way up in the hierarchy, but this is not what I want - besides of undesired side effects (even when doing it temporarily as it may overwrite non-defaults of parents) it also doesn't cause the effect I want without further tweaking, as now overlay views of the shared element appear on top during the transition.
Well, I can step by step modify the example project until it's the same as my actual project, but this is a very tedious task as the actual project is very large and complex. I have done some changes that seem relevant, like adding intermediate views and so on. No success so far.
I simply want to use the overlay. What can be the reason for it not working? Or at least how can I debug this?
I've reproduced this so far on Android M and N. Haven't tested on any other versions.

Transition Effects while Switching Views

I want to switch views by adding a transition effects for Android (No slide transition).
I found the perfect code for IPhone but not for Android.
Can anyone help me with that please?
Here is the link:
http://www.youtube.com/watch?v=Rgnt3auoNw0
There is no easy way like iOS to do view transition in Android. However, it is possible to do so with more code in Android. You can refer to Transition3d example in Android SDK.
Basically you need to start the first half of animation on the view container, make the replaced view invisible and new view visible, and start the second half animation.

How to avoid mixup / clipping of tab layouts (incl. SurfaceView) in TabHost?

In my project I am using a tab host. In one of the tabs there is a Fragment Activity with a Fragment that includes an ImageView with some transparent regions as a background.
Now, in another tab I am incl. the (modified) CaptureActivity of the ZXing QR-Scanner library. I already went through all the hustle of making it work in portrait mode. My issue is, that when I open that one fragment mentioned above (and only in that specific case and order) before the CaptureActivity, the CaptureActivity's layout gets screwed up. The background image of the fragment is shown (although not incl. in this layout) and the camera preview is only shown in the transparent areas, see below.
Now, I don't know if that has to do with the surface view included here.
Somehow it seems to not only be a drawing / clipping issue, because the textview you can see is drawn on top of the surfaceview and is actually orientated android:layout_gravity="bottom|center_horizontal" (and works that way in every other case), but when this issue occurs the textview seems to be getting aligned within the other fragment layout that incl. the partially transparent background imageview.
Any hints are really appreciated. I can post some code if I have a lead what might be the problem here.
Thanks!
In the end I could solve the issue by renaming the drawable-png used as a drawable of the background imageview. Although I checked this before, I don't know if there was a mixup in the ids with the library or maybe I hit some kind of bug.

Android - Animation movement of container does not correctly update contained buttons hitboxes

So I have an application running on Android 2.2 (on a HTC desire). When the user presses the menu key, my menus silkily slide in from top and bottom. This works just great. Or so I thought. It turns out that even when the ImageButtons are off screen and invisible, the hitboxes of the places where they were before I moved them out of sight activate the buttons.
I have tried:
_top_slide_out_menu.forceLayout();
_top_slide_out_menu.recomputeViewAttributes(_measure);
_top_slide_out_menu.computeScroll();
No difference. At a guess it may be because I am moving the parent container object using the animation rather than the buttons themselves. I can only hypothesise that there is a bug that does not update the child hitboxes.
This bug seems to also affect subsequent animations I apply to the button. I have a animation I run on a button that I have previously moved using a different animation. This second animation shrinks then grows the button to give the impression of a click. Only half of the button is redrawn, as that is the half contained within the area of the origional button location.
So the question is, has anyone run into this? Is there anything to try other than moving all the buttons individually (which would get rather tiresome)?
I'd appreciate any ideas at this point!
Thanks
Android animations only shifts the pixels of the UI controls when you add animations to them. To actually update the layout after the animation, you should implement an animation listener and manually update the layout other wise the old layout will still remain with the only the pixels shifted.

Categories

Resources