2017-03-22 1 views
1

Je vais avoir des problèmes avec mon parce que quand j'ouvre l'activité, il est, bloquant la vue enter image description herene pouvez pas cacher feuille de fond, Android

Cela arrive, je pense, en raison de l'attribut XML déclarant le avec 350dp de hauteur:

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/bottom_sheet" 
    android:layout_width="match_parent" 
    android:layout_height="350dp" 
    android:background="?android:attr/windowBackground" 
    android:clipToPadding="true" 
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"> 

la chose est, je ne peux pas changer cette valeur à 0DP parce que la prochaine fois que je tente d'ouvrir le , il n'y a pas , car la hauteur est 0DP, donc ça ne montrera rien. Ma question est, est-il un moyen de déclarer le off? (J'ai essayé de setState à STATE_COLLAPSED mais je n'ai pas travaillé). Bellow est le code Java qui interagit avec la feuille de fond. JAVA:

View bottomSheet = findViewById(R.id.bottom_sheet); 
     mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet); 
     mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); 
     mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { 
      @Override 
      public void onStateChanged(View bottomSheet, int newState) { 
       if (newState == BottomSheetBehavior.STATE_COLLAPSED) { 
        //mBottomSheetBehavior.setPeekHeight(0); 
        //mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); 
        //mBottomSheetBehavior.isHideable(); 
       } 
      } 

      @Override 
      public void onSlide(View bottomSheet, float slideOffset) { 

      } 
     }); 

Répondre

2

écrire ceci:

mBottomSheetBehavior.setPeekHeight(0); 
2

vous devez d'abord ajouter l'attribut

app:behavior_hideable="true" 

dans votre

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/bottom_sheet" 
    android:layout_width="match_parent" 
    android:layout_height="350dp" 
    android:background="?android:attr/windowBackground" 
    android:clipToPadding="true" 
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"> 

Et puis vous pouvez cacher le fond feuille usin g

mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN) 

et non

mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED) 

l'état affaissé est entre HIDDEN et Agrandi et son doit être spécifié heigth par l'attribut:

app:behavior_peekHeight="200dp" 
+0

feuille inférieure ne montre pas quand je setstate se sont effondrés. J'ai l'application: behavior_peekHeight = "200dp" dans le code xml – kemdo

+0

je me demandais juste, votre bottomsheet est un premier enfant dans un CoordinatorLayout? –

0
Inside oncreate add these lines, it can hide the bottombar 

mBottomSheetBehavior = BottomSheetBehavior.from (Feuille inférieure); mBottomSheetBehavior.setHideable (true); // important d'ajouter mBottomSheetBehavior.setState (BottomSheetBehavior.STATE_HIDDEN); // ajouter Important