Hide A Layout After 10 Seconds In Android?

前端 未结 6 474
旧巷少年郎
旧巷少年郎 2021-02-04 07:30

I have a layout displayed on a button click.I want to hide that layout after 10 seconds.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(         


        
6条回答
  •  半阙折子戏
    2021-02-04 08:28

    The following piece of code hides your layout in 3 secs. You can change the time by changing the constant I have provided here for the delay.

             private void HideLayout() {
    
         final View view=volume_control_layout;
         view.postDelayed(new Runnable() {
    
            public void run() {
                if(!volume_controller.isPressed())
                {
                view.setVisibility(View.INVISIBLE);
                }
                else
                {
                    HideLayout();
                }
            }
        }, 3000); // (3000 == 3secs)
    
        }
    

提交回复
热议问题