【问题标题】:Android bottomsheet dialog how to set bottom marginAndroid底页对话框如何设置底边距
【发布时间】:2023-03-23 05:35:02
【问题描述】:

我可以设置底页对话框的左右边距。有什么方法可以将边距放在底部工作表对话框的底部?

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final Dialog d = super.onCreateDialog(savedInstanceState);
        d.setOnShowListener(new DialogInterface.OnShowListener() {
            @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
            @Override
            public void onShow(DialogInterface dialogInterface) {
                View content = d.getWindow().findViewById(R.id.design_bottom_sheet);

                CoordinatorLayout.LayoutParams params = ((CoordinatorLayout.LayoutParams) content.getLayoutParams());
                params.setMargins(getResources().getDimensionPixelSize(R.dimen.fixed_padding_large), 0 ,getResources().getDimensionPixelSize(R.dimen.fixed_padding_large), getResources().getDimensionPixelSize(R.dimen.fixed_padding_large));
                content.setLayoutParams(params);

            }
        });
        return d;
    }

【问题讨论】:

    标签: java android material-design margin bottom-sheet


    【解决方案1】:

    从您的布局设计中尝试使用父布局包装您的内容并将父布局背景设置为透明,然后在您的孩子设置边距底部

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#00000000"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical">
        <androidx.cardview.widget.CardView
            android:layout_marginBottom="10dp"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:cardCornerRadius="10dp"
            app:cardBackgroundColor="#FFFFFF">
    
        </androidx.cardview.widget.CardView>
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    【讨论】:

      猜你喜欢
      • 2012-11-06
      • 1970-01-01
      • 1970-01-01
      • 2019-01-02
      • 1970-01-01
      • 1970-01-01
      • 2014-07-19
      • 2017-08-14
      • 1970-01-01
      相关资源
      最近更新 更多