の解決策ではありません。私はレイアウトの下に含まれているコーディネーターのレイアウトで
BottomSheetBehavior mBottomSheetBehavior = BottomSheetBehavior.from(findViewById(R.id.bottom_pannel_layout));
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
mBottomSheetBehavior.setBottomSheetCallback(mBottomSheetCallback);
活動にxmlファイル: - - :Activityクラスで は、私はこのcommonBottomSheetのためのコードを書いてい
CommonBottomSheetFragmentで
<include layout="@layout/bottom_sheet_pannel"/>
、あなたが作成することができますあなたのレイアウト。
そしてbottomSheetのための私のxmlファイル(bottom_sheet_pannel)は、このようなものです: -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottom_pannel_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:behavior_peekHeight="45dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<ImageView
android:id="@+id/grabber_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/ic_vector_slider_grabber"
android:tint="@color/colorTint" />
<fragment
android:id="@+id/rf_common_details_fragment"
android:layout_marginTop="@dimen/margin_10"
android:name="com.fragment.CommonBottomSheetFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
あなたはコールバック以下でbottomSheetの状態を変更することができます -
private BottomSheetBehavior.BottomSheetCallback mBottomSheetCallback = new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(View bottomSheet, int newState) {
// do what you want on state change
}
@Override
public void onSlide(View bottomSheet, float slideOffset) {
}
};