我这样做,但它没有出现。
@OnClick(R.id.btnMap)
public void click(){
initBottomSheet();
Log.d("TAG", "!!!");
}
private void initBottomSheet() {
bottomSheetBehavior = BottomSheetBehavior.from(layout_bottom);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
bottomSheetBehavior.setPeekHeight(340);
bottomSheetBehavior.setHideable(false);
initBottomSheetStateListener(bottomSheetBehavior);
}
private void initBottomSheetStateListener(@NonNull BottomSheetBehavior bottomSheetBehavior) {
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
}
和标记
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="220dp"
android:background="@drawable/shape_bottom_sheet"
android:orientation="vertical"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
奇怪,直到我问这个问题我才解决问题,但结果很简单