Вот так я начинаю нижний лист:
private fun initBottomSheet() {
llBottomSheet = findViewById(R.id.sheet)
bottomSheetBehavior= BottomSheetBehavior.from(bottomSheet)
bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
bottomSheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) {}
override fun onSlide(bottomSheet: View, slideOffset: Float) {
val upperState = 0.66
val lowerState = 0.33
if (bottomSheetBehavior.state == BottomSheetBehavior.STATE_SETTLING) {
if (slideOffset >= upperState) {
bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
}
if (slideOffset > lowerState && slideOffset < upperState) {
bottomSheetBehavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED
}
if (slideOffset <= lowerState) {
bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
}
}
}
})
changeSize()
}
private fun changeSize() {
val screenHeight = getScreenHeight(this)
bottomSheetBehavior.peekHeight = (screenHeight * 0.2).toInt()
val params: ViewGroup.LayoutParams = llBottomSheet.layoutParams
params.height = (screenHeight * 0.8).toInt()
llBottomSheet.layoutParams = params
}
И у меня проблема. У меня есть нижний лист до 1/3 размера телефона, а когда я блокирую телефон и позже, когда я возобновляю свое приложение, нижний лист go вниз или go до
edit Здесь я кладу свой main_xml
, в который я включаю bottomSheetBehavior
в sheet_map.xml
файл
sheet_map
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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="500sp"
android:background="@drawable/bottom_sheet_behavior"
android:orientation="vertical"
app:behavior_hideable="false"
app:behavior_peekHeight="85dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<androidx.core.widget.NestedScrollView
android:id="@+id/nsv"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/temp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="10sp">
<Button
android:id="@+id/bt_find_connection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bt_state"
android:text="@string/find_connection"
android:textColor="@color/background_tutorial"
android:textSize="@dimen/text_dp_19" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/bt_find_connection">
<LinearLayout
android:id="@+id/user_info_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="5sp">
<ImageView
android:id="@+id/iv_photo"
android:layout_width="50sp"
android:layout_height="50sp"
android:scaleType="centerCrop" />
<RelativeLayout
android:layout_width="0sp"
android:layout_height="wrap_content"
android:layout_marginStart="5sp"
android:layout_marginEnd="5sp"
android:layout_weight="3.5">
<TextView
android:id="@+id/tv_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/background_tutorial"
android:textSize="@dimen/text_dp_19"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_user_mail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_user_name"
android:textColor="@color/background_tutorial"
android:textSize="@dimen/text_dp_16" />
</RelativeLayout>
<ImageView
android:id="@+id/iv_settings"
android:layout_width="50sp"
android:layout_height="50sp" />
</LinearLayout>
<TextView
android:id="@+id/tv_active_tickets"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/user_info_panel"
android:text="@string/active_tickets"
android:textColor="@color/text_color_tutorial"
android:textSize="@dimen/text_dp_12" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list_tickets"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_active_tickets" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout><?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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="500sp"
android:background="@drawable/bottom_sheet_behavior"
android:orientation="vertical"
app:behavior_hideable="false"
app:behavior_peekHeight="85dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<androidx.core.widget.NestedScrollView
android:id="@+id/nsv"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/temp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="10sp">
<Button
android:id="@+id/bt_find_connection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bt_state"
android:text="@string/find_connection"
android:textColor="@color/background_tutorial"
android:textSize="@dimen/text_dp_19" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/bt_find_connection">
<LinearLayout
android:id="@+id/user_info_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="5sp">
<ImageView
android:id="@+id/iv_photo"
android:layout_width="50sp"
android:layout_height="50sp"
android:scaleType="centerCrop" />
<RelativeLayout
android:layout_width="0sp"
android:layout_height="wrap_content"
android:layout_marginStart="5sp"
android:layout_marginEnd="5sp"
android:layout_weight="3.5">
<TextView
android:id="@+id/tv_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/background_tutorial"
android:textSize="@dimen/text_dp_19"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_user_mail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_user_name"
android:textColor="@color/background_tutorial"
android:textSize="@dimen/text_dp_16" />
</RelativeLayout>
<ImageView
android:id="@+id/iv_settings"
android:layout_width="50sp"
android:layout_height="50sp" />
</LinearLayout>
<TextView
android:id="@+id/tv_active_tickets"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/user_info_panel"
android:text="@string/active_tickets"
android:textColor="@color/text_color_tutorial"
android:textSize="@dimen/text_dp_12" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list_tickets"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_active_tickets" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
main xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include layout="@layout/sheet_map" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Я редактирую свой пост и переименовать bottomSheet в bottomSheetBehavior