Skip to content

Commit ab3a776

Browse files
committed
Avoid running layout transitions on unattached views and windows
LayoutTransition causes artifacts in some situations where a window is just becoming visible or a container is just being added to the view tree when animations are kicked off in LayoutTransition due to the normal automatic mechanism of running animations when views are added/removed/etc. The problem is that containers in these situations may have children with positions and sizes of (0, 0), causing the animation to animate from this default/nonsense value to whatever is appropriate for the views when they are first laid out and drawn. The end result is correct, but the animation is superfluous and silly. The fix is to avoid running any kind of transition animation on windows that are not currently visible or containers that are not currently atached to the view hierarchy. This should avoid the situation by only allowing the animations to run after the containers and windows are visible and set up correctly. Issue #6544410 issue with layout transition when first showing the activity Change-Id: I737b2598887ef806dec3b02a483a8e8ff2c3d4e2
1 parent 53d003f commit ab3a776

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

core/java/android/animation/LayoutTransition.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,9 @@ public void onAnimationEnd(Animator anim) {
12081208
* affect CHANGE_APPEARING or CHANGE_DISAPPEARING animations.
12091209
*/
12101210
private void addChild(ViewGroup parent, View child, boolean changesLayout) {
1211+
if (parent.getWindowVisibility() != View.VISIBLE) {
1212+
return;
1213+
}
12111214
if ((mTransitionTypes & FLAG_APPEARING) == FLAG_APPEARING) {
12121215
// Want disappearing animations to finish up before proceeding
12131216
cancel(DISAPPEARING);
@@ -1243,6 +1246,9 @@ private void addChild(ViewGroup parent, View child, boolean changesLayout) {
12431246
* @hide
12441247
*/
12451248
public void layoutChange(ViewGroup parent) {
1249+
if (parent.getWindowVisibility() != View.VISIBLE) {
1250+
return;
1251+
}
12461252
if ((mTransitionTypes & FLAG_CHANGING) == FLAG_CHANGING && !isRunning()) {
12471253
// This method is called for all calls to layout() in the container, including
12481254
// those caused by add/remove/hide/show events, which will already have set up
@@ -1301,6 +1307,9 @@ public void showChild(ViewGroup parent, View child, int oldVisibility) {
13011307
* affect CHANGE_APPEARING or CHANGE_DISAPPEARING animations.
13021308
*/
13031309
private void removeChild(ViewGroup parent, View child, boolean changesLayout) {
1310+
if (parent.getWindowVisibility() != View.VISIBLE) {
1311+
return;
1312+
}
13041313
if ((mTransitionTypes & FLAG_DISAPPEARING) == FLAG_DISAPPEARING) {
13051314
// Want appearing animations to finish up before proceeding
13061315
cancel(APPEARING);

0 commit comments

Comments
 (0)