7

23.4.0 sürümünden Android Design Support kütüphanesinin 24.2.1 sürümüne geçtikten sonra BottomSheetBehavior benim için çalışmayı durdurdu. BottomSheet açık olarak gösterir ve setState(BottomSheetBehavior.STATE_COLLAPSED) numaralı telefonu ararken kapanmaz. Bu, BottomSheetBehaviour'un beklendiği gibi benim için çalıştığı Tasarım kitaplığının 23.4.0'ında gerçekleşmez.Android Tasarım Destek Kitaplığı 24.2.1, BottomSheet'i başlangıçta açar

BottomSheetBehavior kullanılmasını gerektiren 24 sürümünde herhangi bir değişiklik oldu mu? İşte

benim düzen dosyasıdır:

<?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"/> 

Ve burada kullanıyorum Etkinlik kodudur:

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; 
    } 
} 

}

Herhangi bir tavsiye memnuniyetle karşılanacaktır.

+0

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

cevap

11
m_behaviour.setPeekHeight(0); 
"gözetleme" durumuna

öntanımlıdır, bunu hiç gözetleme istemiyorsanız, sen 0.

+0

Teşekkürler, Scott. Başlangıçta m_behaviour.setPeekHeight (0) ayarlandığında, örn. onCreate() içinde –

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

için gözetleme yüksekliğini ayarlamak gerekir böylece ayarlayabilirsiniz düzende 0dp için peek yüksekliği, programsal olarak ayarlamanıza gerek yok

İlgili konular