Why is view.bringToFront () not working?

I have a RelativeLayout on which I have controls on top. At runtime, I want to show a MapView that is just added to the layout, hiding all the other views below it, but not the controls on top. Later, MapView hides again.

layout_main.bringChildToFront(layout_main.findViewWithTag("paramsUI"));
layout_main.invalidate();

FindViewByTag seems to work, I checked this in Debug mode. I also tried:

layout_main.findViewWithTag("paramsUI").bringToFront();

Do I need something else?

Edit: Sorry, the problem is that MapView is hiding the control panel, which should be at the top of all views due to the call to bringToFront ().

+5
source share
4 answers

RelativeLayout LinearLayout, LinearLayout. , , RelativeLayout, .

0

, FrameLayout, RelativeLayout. A RelativeLayout , FrameLayout . , , .

FrameLayout:

Child , . FrameLayout - ( ), ( FrameLayout). GONE , setConsiderGoneChildrenWhenMeasuring() true.

, ! , .

0

For Android 4.x, you need to call requestLayout () between two calls:

layout_main.bringChildToFront(layout_main.findViewWithTag("paramsUI"));
layout_main.requestLayout();
layout_main.invalidate();
0
source

You can try this code. It seems to need to work on old and new versions of Android

if (android.os.Build.VERSION.SDK_INT >= 21) //Lollipop
{
    view.setZ(5);

    for (int i = 0; i < view.getParent().getChildCount(); i++)
    {
        if(view != view.getParent().getChildAt(i))
        {
            view.getParent().getChildAt(i).setZ(4);
        }
    }
}

view.bringToFront();
for (int i = 0; i < view.getParent().getChildCount(); i++)
{
    view.getParent().getChildAt(i).invalidate();
}
view.getParent().requestLayout();
view.getParent().invalidate();
0
source

All Articles