How to bring view in front of everything?

后端 未结 16 2190
刺人心
刺人心 2020-11-30 01:31

I have activity and a lot of widgets on it, some of them have animations and because of the animations some of the widgets are moving (translating) one over another. For exa

相关标签:
16条回答
  • 2020-11-30 02:12

    Try FrameLayout, it gives you the possibility to put views one above another. You can create two LinearLayouts: one with the background views, and one with foreground views, and combine them using the FrameLayout. Hope this helps.

    0 讨论(0)
  • 2020-11-30 02:15

    An even simpler solution is to edit the XML of the activity. Use

    android:translationZ=""
    
    0 讨论(0)
  • 2020-11-30 02:15

    Thanks to Stack user over this explanation, I've got this working even on Android 4.1.1

    ((View)myView.getParent()).requestLayout();
    myView.bringToFront();
    

    On my dynamic use, for example, I did

    public void onMyClick(View v)
         {
         ((View)v.getParent()).requestLayout();
         v.bringToFront();
         }
    

    And Bamm !

    0 讨论(0)
  • 2020-11-30 02:17

    There can be another way which saves the day. Just init a new Dialog with desired layout and just show it. I need it for showing a loadingView over a DialogFragment and this was the only way I succeed.

    Dialog topDialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);
    topDialog.setContentView(R.layout.dialog_top);
    topDialog.show();
    

    bringToFront() might not work in some cases like mine. But content of dialog_top layout must override anything on the ui layer. But anyway, this is an ugly workaround.

    0 讨论(0)
提交回复
热议问题