簡體   English   中英

如何在布局底部膨脹對話框?

[英]How do I inflate dialog at the bottom of my layout?

我的滑動關閉對話框當前顯示在與父級寬度匹配的布局的中心。 沒有左/右頁邊距。 我想把它放在底部。

這是我的 XML 布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_fmcg_popup"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_gravity="bottom"
    android:layout_weight="1"
    android:background="@drawable/button_border">

    <android.support.constraint.ConstraintLayout
        android:id="@+id/main_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="17dp"
        android:layout_marginTop="13dp"
        android:layout_marginEnd="17dp"
        android:layout_marginBottom="13dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

      // other code goes here

    </android.support.constraint.ConstraintLayout>

</android.support.constraint.ConstraintLayout>

這是滑動以關閉對話框的代碼。 我目前正在使用滑動來關閉對話框庫。

 View dialog = LayoutInflater.from(this).inflate(R.layout.dialog_fmcg_popup, null);
                        TextView tvfmcg2 = dialog.findViewById(R.id.tv_fmcg2);
                        tvfmcg2.setText(message);
                        swipeDismissDialog = new SwipeDismissDialog.Builder(this)
                                .setView(dialog)
                                .setOnSwipeDismissListener(new OnSwipeDismissListener() {
                                    @Override
                                    public void onSwipeDismiss(View view, SwipeDismissDirection direction) {
                                        Preferences.setString(Prefkey.last_qualified_fmcg_voucher_on_remove, message);
                                    }
                                })
                                .setFlingVelocity(0)
                                .setOverlayColor(0)
                                .build()
                                .show();
                    }

您可以嘗試以下代碼,這將在屏幕底部顯示對話框:

  Dialog dialog
    //code to initialize dialog here

    Window window = dlg.getWindow();
    WindowManager.LayoutParams wlp = window.getAttributes();

    wlp.gravity = Gravity.BOTTOM;
    wlp.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
    window.setAttributes(wlp);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM