Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 底部图纸的隐藏状态_Android_Bottom Sheet - Fatal编程技术网

Android 底部图纸的隐藏状态

Android 底部图纸的隐藏状态,android,bottom-sheet,Android,Bottom Sheet,我正在尝试为底部工作表设置隐藏状态,但它不起作用。有什么问题吗 bottomBar = BottomSheetBehavior.from(findViewById(R.id.bottom_bar)); bottomBar.setState(BottomSheetBehavior.STATE_HIDDEN); 尝试bottomsheetbehavior.STATE\u COLLAPSED bottomBar = BottomSheetBehavior.from(findViewById(R.

我正在尝试为
底部工作表设置隐藏状态,但它不起作用。有什么问题吗

 bottomBar = BottomSheetBehavior.from(findViewById(R.id.bottom_bar));
 bottomBar.setState(BottomSheetBehavior.STATE_HIDDEN);

尝试
bottomsheetbehavior.STATE\u COLLAPSED

bottomBar = BottomSheetBehavior.from(findViewById(R.id.bottom_bar));
bottomBar.setState(BottomSheetBehavior.STATE_COLLAPSED);

确保在活动的生命周期中不要过早地这样做。如果需要在
onCreate
或类似程序中执行此操作,请尝试将其放置在发布到视图的
Runnable
中,如下所示:

getWindow().getDecorView().post(new Runnable() {
    @Override
    public void run() {
        bottomBar = BottomSheetBehavior.from(findViewById(R.id.bottom_bar));
        bottomBar.setState(BottomSheetBehavior.STATE_HIDDEN);
    }
 });
这不是最干净的解决方案,但有时是不可避免的。

尝试以下方法:

LinearLayout bottomSheetViewgroup  
= (LinearLayout) findViewById(R.id.bottom_sheet);

BottomSheetBehavior bottomSheetBehavior =  
BottomSheetBehavior.from(bottomSheetViewgroup);
然后使用

bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);

记住在活动/片段开始时隐藏底部工作表时添加此项

bottomSheetBehavior =BottomSheetBehavior.from(bottom_sheet_view_here);
bottomSheetBehavior.setHideable(true);//Important to add
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);

使用此选项,它将隐藏。

如果您使用类似于选项卡式活动的内容,您可以在片段中隐藏bottomsheetlayout

我认为这是可能的,因为片段视图是在活动视图之后创建的

class "activity"
   public void hideBottomSheet(){ 
      sheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
   }

class "fragment"
   onCreateView()
      ((YourActivity.class)getActivity()).hideBottomSheet();
另一种方式- 这样您就不需要
片段了

boolean init = true;


layoutBottomSheet.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View view, int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7) {
            if(init)hideBottomSheet();
            init=false;
        }
    });
要使用小动画隐藏,请执行以下操作:)


在活动生命周期的什么时候执行此操作?onCreate()方法要隐藏底部工作表,用户可以向下滑动以将其隐藏在屏幕上,或者您可以将底部工作表行为设置为“状态”\u COLLAPSEDSTATE\u COLLAPSED不起作用”。当调用hide()方法时,我想像ActionBar一样隐藏底部表单。SetHidable(true)是我想要的东西哇。。。默认情况下应该是这样的。这是所有解决方案中唯一对我有效的方法。
boolean init = true;


layoutBottomSheet.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View view, int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7) {
            if(init)hideBottomSheet();
            init=false;
        }
    });
 bottomsheetbehavior.setPeekHeight(0, true);
            bottomSheet.animate()
                    .translationYBy(bottomSheetBehavior.getPeekHeight());