gpt4 book ai didi

android - Bottomsheet 占据全屏

转载 作者:行者123 更新时间:2023-11-29 19:13:12 39 4
gpt4 key购买 nike

我试图不让 BottomSheet 填充整个屏幕,而是在展开时在上方留出一些空间。这是我的 onExpand 填充整个屏幕的代码。

bottomSheetBehavior = BottomSheetBehavior.from(bottomLayout);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);

bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
switch (newState) {
case BottomSheetBehavior.STATE_DRAGGING:
Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_DRAGGING");
break;
case BottomSheetBehavior.STATE_SETTLING:
Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_SETTLING");
break;
case BottomSheetBehavior.STATE_EXPANDED:
Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_EXPANDED");
break;
case BottomSheetBehavior.STATE_COLLAPSED:
Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_COLLAPSED");
break;
case BottomSheetBehavior.STATE_HIDDEN:
Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_HIDDEN");
break;

}
}

@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
Log.i("BottomSheetCallback", "slideOffset: " + slideOffset);
boolean drawer = getSupportFragmentManager().getBackStackEntryCount() == 0;
ObjectAnimator.ofFloat(drawerArrow, "progress", drawer ? 0 : 1).start();
}
});


bottomLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Log.v(TAG, "ONCLickListner");

if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
Log.v(TAG,"state expand");
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
} else {
Log.v(TAG,"state collapse");
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}

}
});

能否请您解决我的问题并提出一种方法,使 Bottom Sheet 不占据整个屏幕,而是在展开时在上方留出一些空间。谢谢

最佳答案

一个简单的技巧就完成了。我现在无法阻止 Bottom Sheet 全屏显示,所以我有一个对我所需大小透明的 View ,通过将它添加到 bottomSheetLayout 解决了我的问题

<View
android:layout_width="match_parent"
android:id="@+id/spaccer"
android:layout_height="28dp"
android:background="@android:color/transparent"
android:alpha="0.6"/>

关于android - Bottomsheet 占据全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44492537/

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