7

Po przejściu do wersji 24.2.1 biblioteki pomocy technicznej Android Design od wersji 23.4.0 BottomSheetBehavior przestał działać dla mnie. Dolny arkusz jest wyświetlany jako otwarty i nie zamyka się podczas wywoływania setState(BottomSheetBehavior.STATE_COLLAPSED). Nie dzieje się to w 23.4.0 biblioteki Design, gdzie BottomSheetBehaviour działa zgodnie z oczekiwaniami.Biblioteka pomocy projektowania Androida 24.2.1 otwiera okno BottomSheet przy uruchomieniu

Czy coś zmieniło się w wersji 24, która wymaga inaczej używania BottomSheetBehavior?

Oto mój plik układ:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/button" 
     android:text="Open Bottom Sheet" 
     /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/close_button" 
     android:text="Close Bottom Sheet" 
     /> 

</LinearLayout> 
<LinearLayout 
    android:id="@+id/bottom_sheet" 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:orientation="horizontal" 
    android:background="@android:color/holo_green_light" 
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"/> 

A oto kod aktywny że używam:

public class ScrollingActivity extends AppCompatActivity implements View.OnClickListener { 

private View m_bottomSheet; 
private BottomSheetBehavior m_behaviour; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_scrolling); 

    m_bottomSheet = findViewById(R.id.bottom_sheet); 
    m_behaviour = BottomSheetBehavior.from(m_bottomSheet); 


    ((Button)findViewById(R.id.button)).setOnClickListener(this); 
    ((Button)findViewById(R.id.close_button)).setOnClickListener(this); 
} 
@Override 
public void onClick(View v) { 
    switch(v.getId()){ 
     case R.id.button: 
      m_behaviour.setState(BottomSheetBehavior.STATE_EXPANDED); 
      break; 
     case R.id.close_button: 
      m_behaviour.setState(BottomSheetBehavior.STATE_COLLAPSED); 
      break; 
    } 
} 

}

Każda rada byłaby doceniona.

+0

http://stackoverflow.com/questions/39030742/bottomsheetbehavior-is-not-work-when-design-library-update-to-24-2 -0 –

Odpowiedz

11
m_behaviour.setPeekHeight(0); 

domyślnie przyjmuje się tzw „peek” stanie, więc jeśli nie chcesz, aby zajrzeć w ogóle, trzeba ustawić wysokość peek 0.

+0

Dzięki, Scott. Działało zgodnie z zamierzeniami podczas początkowego ustawiania m_behaviour.setPeekHeight (0), np. w onCreate() –

2
app:behavior_peekHeight="0dp" 
app:layout_behavior="@string/bottom_sheet_behavior" 

Można ustawić wysokość podglądu do 0pp w układzie, nie trzeba go programować

Powiązane problemy