gpt4 book ai didi

android - 如何在 BottomSheetDialog 中的 GridView 中向上滚动?

转载 作者:太空宇宙 更新时间:2023-11-03 13:45:57 25 4
gpt4 key购买 nike

我创建了一个 BottomSheetDialog,其中有一个 GridViewBottomSheetDialog 打开时,您可以正常向下 滚动。这样做会使 BottomSheetDialog 扩展到全屏并在 GridView 中正常向下滚动。

然而,当用户试图向上滚动时; GridView 不会向上滚动,BottomSheetDialog 会收缩并关闭。

我想要的是能够在 GridView 中上下滚动而无需 BottomSheetDialog 更改大小。

怎么做?

我的代码:

final BottomSheetDialog dialog = new BottomSheetDialog(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.grid, null);
dialog.setContentView(view);

网格.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">

<GridView
android:background="#FFFFFF"
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
android:stretchMode="columnWidth"
android:horizontalSpacing="4dp"
android:verticalSpacing="4dp"
android:gravity="center"
/>

</LinearLayout>

最佳答案

已解决:

dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(final DialogInterface dialog) {
BottomSheetDialog d = (BottomSheetDialog) dialog;
FrameLayout bottomSheet = (FrameLayout) d.findViewById(android.support.design.R.id.design_bottom_sheet);
// Right here!
final BottomSheetBehavior behaviour = BottomSheetBehavior.from(bottomSheet);
behaviour.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_HIDDEN) {
dialog.dismiss();
}

if (newState == BottomSheetBehavior.STATE_DRAGGING) {
((BottomSheetBehavior) behaviour).setState(BottomSheetBehavior.STATE_EXPANDED);
}
}

@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {

}
});
}
});

关于android - 如何在 BottomSheetDialog 中的 GridView 中向上滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42247094/

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