Android: When setting new parent for childView remove old one
A view cannot have two parents. If the view already has a parent, you must first call removeView() on the child's parent. Fixes: QTBUG-129524 Pick-to: 6.7 Change-Id: I6a8340ed8db58a77626be17366d5c71bdfc8c762 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit ecd4623f05abf419db6f0c3bdad406c1883b6509) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
68c22bd7d3
commit
e3bea87ee3
@ -13,6 +13,7 @@ import android.view.Display;
|
|||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ViewParent;
|
||||||
|
|
||||||
class QtLayout extends ViewGroup {
|
class QtLayout extends ViewGroup {
|
||||||
|
|
||||||
@ -201,14 +202,19 @@ class QtLayout extends ViewGroup {
|
|||||||
if (!checkLayoutParams(params))
|
if (!checkLayoutParams(params))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
final ViewParent parent = childView.getParent();
|
||||||
|
|
||||||
// View is already in the layout and can therefore be updated
|
// View is already in the layout and can therefore be updated
|
||||||
final boolean canUpdate = (this == childView.getParent());
|
final boolean canUpdate = (this == parent);
|
||||||
|
|
||||||
if (canUpdate) {
|
if (canUpdate) {
|
||||||
childView.setLayoutParams(params);
|
childView.setLayoutParams(params);
|
||||||
if (forceRedraw)
|
if (forceRedraw)
|
||||||
invalidate();
|
invalidate();
|
||||||
} else {
|
} else {
|
||||||
|
// If the parent was already set it need to be removed first
|
||||||
|
if (parent != null && parent instanceof ViewGroup)
|
||||||
|
((ViewGroup)parent).removeView(childView);
|
||||||
addView(childView, params);
|
addView(childView, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user