dialog底部自动弹出

/**
* 自定义弹出框 默认打开 动画效果为从底部弹出

* public void showPopWindow() {
MobclickAgent.onEvent(MainA.this, "CLICK_ME");// 点我
if (MyApplication.getPerferenceUtil().containKey(Constant.SCHEDULE_STATUS)) {
Text_chooseCar.setText("正在订车");
} else {
Text_chooseCar.setText("快捷订车");
}
if (dialog == null) {
dialog = MyTools.showAutoDialog(MainA.this, tab6View, Gravity.BOTTOM, 0.0, 0.0);
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
} else {
dialog.show();
}
}


*/
public static Dialog showAutoDialog(Activity context, View view, int position, double width, double height) {
android.app.AlertDialog dialog = new android.app.AlertDialog.Builder(context).create();


if (MyTools.isRunningForeground(context)) {
dialog.show();
}


// 关键在下面的两行,使用window.setContentView,替换整个对话框窗口的布局
Window window = dialog.getWindow();
window.setContentView(view);
window.setGravity(position); // 此处可以设置dialog显示的位置
// 对dialog的窗口大小进行设置
WindowManager m = context.getWindowManager();
Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
WindowManager.LayoutParams p = window.getAttributes(); // 获取对话框当前的参数值
if (width != 0.0) {
p.width = (int) (d.getWidth() * width);
} else {
p.width = (int) d.getWidth();
}
if (height != 0.0) {
p.height = (int) (d.getHeight() * height);
}
window.setAttributes(p);
if (position == Gravity.BOTTOM) {


window.setWindowAnimations(R.style.c_anim_move_bt);
}


return dialog;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你想要实现一个从底部动弹的对话框,可以尝试以下步骤: 1. 创建一个 `QDialog` 对象,并将其固定在底部位置,例如设置其 `Qt::BottomDockWidgetArea` 属性为 `true`。可以使用 `QWidget::setGeometry()` 函数进行设置。 2. 在对话框的构造函数中,将其隐藏,例如使用 `QDialog::hide()` 函数。 3. 在需要弹对话框的时候,使用 `QPropertyAnimation` 类创建一个动画对象,并在其中设置对话框的位置和大小属性。例如,可以设置对话框的位置从底部移动到屏幕中心,同时设置对话框的大小从 0 变为适当的大小。 4. 在动画结束后,使用 `QDialog::exec()` 函数让对话框显示,并等待其关闭。 以下是一个示例代码,可以实现一个从底部动弹的对话框: ```cpp #include <QDialog> #include <QPropertyAnimation> class SlidingDialog : public QDialog { public: SlidingDialog(QWidget *parent = nullptr) : QDialog(parent) { // 设置对话框的初始位置和大小 setGeometry(parent->geometry().left(), parent->geometry().bottom() - 50, parent->geometry().width(), 0); // 将对话框设为 BottomDockWidgetArea 类型 setAttribute(Qt::WA_ShowWithoutActivating); setWindowFlags(Qt::FramelessWindowHint | Qt::BottomDockWidgetArea); // 隐藏对话框 hide(); } void showAnimated() { // 创建动画对象,设置对话框的位置和大小属性 QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry"); animation->setDuration(500); animation->setStartValue(geometry()); animation->setEndValue(QRect((parentWidget()->width() - width()) / 2, (parentWidget()->height() - height()) / 2, width(), height())); // 显示对话框 show(); // 开始动画 animation->start(QAbstractAnimation::DeleteWhenStopped); // 等待对话框关闭 exec(); } }; ``` 使用时,可以在需要弹对话框的地方创建一个 `SlidingDialog` 对象,并调用其 `showAnimated()` 函数即可: ```cpp void MainWindow::on_btnOpenDialog_clicked() { // 创建一个 SlidingDialog 对象,并调用其 showAnimated() 函数 SlidingDialog *dialog = new SlidingDialog(this); dialog->setFixedSize(200, 100); dialog->showAnimated(); } ``` 需要注意的是,该示例中的对话框是固定在底部位置的,如果需要弹在其他位置,则需要对代码进行适当修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值