zoukankan      html  css  js  c++  java
  • Android 自定义dialog出现的位置

    跟 https://www.cnblogs.com/guochangxin/p/11457537.html 配套

    1、定义一个dialog的类

    public class OtherDialog {
    private View view;

    public Dialog showOtherDialog(Context context) {
    //1、使用Dialog、设置style
    final Dialog dialog = new Dialog(context, R.style.DialogTheme);
    //2、设置布局
    view = View.inflate(context, R.layout.news_bottom_dialog, null);
    dialog.setContentView(view);

    Window window = dialog.getWindow();
    //设置弹出位置
    window.setGravity(Gravity.TOP);

    int matchParent = ViewGroup.LayoutParams.MATCH_PARENT;//父布局的宽度

    Window dialogWindow = dialog.getWindow();
    dialogWindow.setGravity(Gravity.TOP | Gravity.RIGHT);
    WindowManager.LayoutParams lp = dialogWindow.getAttributes();
    lp.width = matchParent;
    lp.height = matchParent;
    lp.x = matchParent;
    lp.y = 300; //设置出现的高度,距离顶部
    window.setAttributes(lp);

    //设置弹出动画
    // window.setWindowAnimations(R.style.main_menu_animStyle);
    //设置对话框大小
    window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    dialog.show();

    return dialog;


    }
    }

    2、使用
    private OtherDialog otherDialog=new OtherDialog();//实例化
    otherDialog.showOtherDialog(getContext());


  • 相关阅读:
    mysql常用语句集锦
    PHP 面向对象
    PHP 数组
    PHP 语句 函数 字符串处理
    PHP 随笔
    mysql常用函数
    数据库 创建 查询 练习
    HTML JavaScript语法练习
    HTML JavaScript练习
    随机数生成的简单原理
  • 原文地址:https://www.cnblogs.com/guochangxin/p/11471323.html
Copyright © 2011-2022 走看看