gpt4 book ai didi

android - Android BottomSheetBehavior setPeekHeight(int peekHeight,boolean animate)不设置高度过渡的动画

转载 作者:行者123 更新时间:2023-12-02 13:44:00 24 4
gpt4 key购买 nike

我的BottomSheetBehavior布局看起来像这样:

<LinearLayout
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="match_parent"
android:background="@color/white"
android:orientation="vertical"
app:behavior_hideable="false"
app:behavior_peekHeight="76dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

<LinearLayout
android:id="@+id/bottomSheetPeekLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/bottomSheetEditText"
android:layout_width="match_parent"
android:layout_height="44dp"
android:layout_margin="16dp"/>

<include
android:id="@+id/bottomSheetDynamicHeightLayout"
layout="@layout/layout_bottom_sheet_dynamic_height"
android:visibility="gone" />
</LinearLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/bottomSheetRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</LinearLayout>


嵌入到Activity中的 CoordinatorLayout中:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<FrameLayout
android:layout_width="match_parent"
android:layout_height="44dp"
android:background="@color/white">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/closeIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="4dp"
android:padding="12dp"
android:src="@drawable/ic_close_point_chooser" />

<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textAllCaps="true"
android:textColor="#3f454e"
android:textSize="14sp" />

</FrameLayout>

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/mapFragmentContainerView"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true" />

<include
android:id="@+id/bottomSheetLayout"
layout="@layout/bottom_sheet_layout"
android:paddingTop="44dp" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

</LinearLayout>

应根据 bottomSheetDynamicHeightLayout的高度更改BottomSheet的窥视高度,这是显示一些数据的约束布局。我观察到此布局的高度变化,并通过以下方式更新BottomSheetBehavior:

bottomSheetPeekLayout.addOnLayoutChangeListener { v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom ->
bottomSheetBehavior.setPeekHeight(bottomSheetPeekLayout.height, true)
}

因此,当我的 View 高度发生变化时,将使用 setPeekHeight(int peekHeight, boolean animate) methood来更改BottomSheet窥视高度,根据文档的说明,应该为高度变化设置动画。

但是,这种情况不会发生-窥视高度会更新, Bottom Sheet 会改变窥视大小,但是没有动画-只会改变屏幕大小。当我以前使用此方法来手动更新高度(不在 onLayoutChangedListener中)时,动画工作正常。

有什么我想念的吗?这是某种错误还是所需的行为? animate参数不应该总是为过渡设置动画吗?我如何归档所需的效果?

最佳答案

我遇到了类似的问题,不确定使用以下方法直接解决方案:

setPeekHeight(int peekHeight, boolean animate)


但是,您可以使用过渡管理器添加过渡,如下所示:
TransitionManager.beginDelayedTransition(bottomSheet);
bottomSheetBehavior.setPeekHeight(20);
如果要更改翻译的持续时间,请改用以下内容:
ChangeBounds transition = new ChangeBounds();
transition.setDuration(200L);
TransitionManager.beginDelayedTransition(bottomSheet, transition);
bottomSheetBehavior.setPeekHeight(20);
根据以下答案:
  • animateLayoutChanges="true" in BottomSheetView showing unexpected behaviour
  • Is it possible to set transition speed/time in transition everywhere on android
  • 关于android - Android BottomSheetBehavior setPeekHeight(int peekHeight,boolean animate)不设置高度过渡的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60779005/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com