gpt4 book ai didi

java - 如何在布局底部展开对话框?

转载 作者:行者123 更新时间:2023-12-01 18:35:23 25 4
gpt4 key购买 nike

我的滑动关闭对话框当前显示在布局的中心,与父级的宽度相匹配。无左/右页边距。我想把它放在底部。

这是我的 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);

关于java - 如何在布局底部展开对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60068625/

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