BottomSheetDialog高度不足够显示全部内容的解决办法

  1首先在style文件中:

 

<style name="BottomSheetDialog" parent="Theme.Design.Light.BottomSheetDialog">
    <item name="bottomSheetStyle">@style/bottomSheetStyleWrapper</item>
</style>

<style name="bottomSheetStyleWrapper" parent="Widget.Design.BottomSheet.Modal">
    <item name="behavior_peekHeight">500dp</item>
</style>

 

2:然后再创建的地方引用这个style创建BottomSheetDialog 

 

 

public PrinterMenuDialog(@NonNull Context context) {
    super(context,R.style.BottomSheetDialog);
    initView();
}

这样弹出高度解决了

3:时隔多年回来看这个帖子,看源码得到新的解决思路

布局文件:

<LinearLayout
    android:id="@+id/content_layout"
    android:layout_width="match_parent"
    android:layout_height="@dimen/px_435"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="@dimen/px_50"
        android:text="确 认 切 换"
        android:textColor="@color/white"
        android:background="@drawable/seletor_btn"/>
</LinearLayout>

 

java 文件:

package com.hytch.fthire.widgets;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.view.View;
import android.widget.FrameLayout;

import com.hytch.fthire.R;

/**
 * author : xubaipei
 * create date: 2019-05-22
 */
public class BottomDialog extends BottomSheetDialog {
    int peekHeight = 0;

    public BottomDialog(@NonNull Context context) {
        super(context);
    }

    public BottomDialog(@NonNull Context context, int theme) {
        super(context, theme);
    }

    public BottomDialog(@NonNull Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onStart() {
        super.onStart();

    }

    @Override
    public void show() {
        super.show();
        if (peekHeight == 0){
            View container = findViewById(R.id.content_layout);
            container.measure(0,0);
            peekHeight = container.getMeasuredHeight();

            FrameLayout bottomSheet = (FrameLayout)findViewById(android.support.design.R.id.design_bottom_sheet);
            BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
            behavior.setPeekHeight(peekHeight);
        }
    }
}

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值