Android的扩展BottomSheetDialogFragment折叠开始的偏移距离。
创始人
2024-10-07 07:01:16
0

要给Android的扩展BottomSheetDialogFragment设置折叠开始的偏移距离,可以按照以下步骤进行:

首先,在你的项目中添加BottomSheetDialogFragment库的依赖。在app的build.gradle文件中添加以下依赖项:

implementation 'com.google.android.material:material:1.3.0'

接下来,创建一个继承自BottomSheetDialogFragment的自定义类。在这个类中,你可以设置折叠开始的偏移距离。以下是一个示例:

import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

public class CustomBottomSheetDialogFragment extends BottomSheetDialogFragment {

    @Override
    public void onStart() {
        super.onStart();
        
        // 获取底部折叠布局的Behavior
        BottomSheetBehavior bottomSheetBehavior = getBottomSheetBehavior();

        // 设置折叠开始的偏移距离
        bottomSheetBehavior.setPeekHeight(300); // 这里设置为300px,你可以根据需要进行调整
    }

    private BottomSheetBehavior getBottomSheetBehavior() {
        View view = getView();
        if (view != null) {
            BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from((View) view.getParent());
            return bottomSheetBehavior;
        }
        return null;
    }
}

在上面的示例代码中,我们在CustomBottomSheetDialogFragment的onStart方法中获取了底部折叠布局的Behavior,并设置了折叠开始的偏移距离为300px。你可以根据实际需求进行调整。

最后,在你的Activity或Fragment中使用CustomBottomSheetDialogFragment,如下所示:

CustomBottomSheetDialogFragment bottomSheetDialogFragment = new CustomBottomSheetDialogFragment();
bottomSheetDialogFragment.show(getSupportFragmentManager(), bottomSheetDialogFragment.getTag());

通过上述步骤,你就可以在Android的扩展BottomSheetDialogFragment中设置折叠开始的偏移距离了。

相关内容

热门资讯

透视黑科技!wepoker透视... 透视黑科技!wepoker透视底牌脚本,德普之星辅助工具如何设置,方针教程(果然真的有挂)-哔哩哔哩...
透视新版!德州透视插件(透视)... 透视新版!德州透视插件(透视)开挂辅助脚本(都是是有挂)-哔哩哔哩1、该软件可以轻松地帮助玩家将德州...
透视辅助!aapoker怎么开... 透视辅助!aapoker怎么开辅助器,aapoker ai插件,要领教程(真是是有挂)-哔哩哔哩1、...
透视攻略!wpk插件辅助,we... 透视攻略!wpk插件辅助,wepoker透视破解版,操作教程(好像真的有挂)-哔哩哔哩1、上手简单,...
透视识别!德普之星的辅助工具介... 透视识别!德普之星的辅助工具介绍(透视)开挂辅助工具(一贯真的有挂)-哔哩哔哩1、下载好德普之星的辅...
透视ai代打!wepoker手... 透视ai代打!wepoker手机版辅助,werplan免费挂下载,模块教程(其实存在有挂)-哔哩哔哩...
透视中牌率!wpk透视辅助方法... 透视中牌率!wpk透视辅助方法(透视)开挂辅助神器(一直是有挂)-哔哩哔哩1、wpk透视辅助方法机器...
透视透视!hhpoker透视脚... 透视透视!hhpoker透视脚本视频,德普之星透视,方式教程(切实是有挂)-哔哩哔哩hhpoker透...
透视智能ai!hhpoker免... 透视智能ai!hhpoker免费透视脚本,pokemmo辅助器,策略教程(果然有挂)-哔哩哔哩1、进...
透视测试!wejoker黑侠辅... 透视测试!wejoker黑侠辅助器(透视)开挂辅助方法(一直存在有挂)-哔哩哔哩1、wejoker黑...