Skip to content

Commit

Permalink
add parent child relative
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev4Mod committed Nov 14, 2024
1 parent f149751 commit 1a63a4c
Showing 1 changed file with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,23 +202,24 @@ private void setRuleInView(RuleItem ruleItem, View view) {
for (var declaration : ruleItem.rule) {
var property = declaration.getProperty();
switch (property) {
case "position" -> {
case "parent" -> {
var value = declaration.get(0).toString().trim();
if ("relative".equals(value)) {
var parentView = (ViewGroup) view.getParent();
if (parentView != null) {
if (!(parentView instanceof FrameLayout) && parentView.getTag() != "relative") {
var frameLayout = new FrameLayout(parentView.getContext());
frameLayout.setTag("relative");
var params = new FrameLayout.LayoutParams(view.getLayoutParams());
var viewRoot = (ViewGroup) view.getRootView();
viewRoot.addView(frameLayout, params);
parentView.removeView(view);
frameLayout.addView(view);
view = frameLayout;
} else if (parentView.getTag() == "relative") {
view = parentView;
}
var parent = view.getRootView();
if (!"root".equals(value)) {
parent = parent.findViewById(Utils.getID(value, "id"));
}
if (parent instanceof ViewGroup parentView) {
var oldParent = (View) view.getParent();
if (oldParent.getTag() != "relative") {
((ViewGroup) view.getParent()).removeView(view);
var frameLayout = new FrameLayout(parentView.getContext());
frameLayout.setTag("relative");
var params = new FrameLayout.LayoutParams(view.getLayoutParams());
parentView.addView(frameLayout, 0, params);
frameLayout.addView(view);
view = frameLayout;
} else if (oldParent.getTag() == "relative") {
view = oldParent;
}
}
}
Expand Down

0 comments on commit 1a63a4c

Please sign in to comment.