【问题标题】:How to define gravity of a Dialog Fragment?如何定义对话框片段的重力?
【发布时间】:2020-12-12 18:29:09
【问题描述】:

我希望我的对话一直停留在开头,但它总是出现在中间。

【问题讨论】:

    标签: android-dialogfragment dialogfragment


    【解决方案1】:

    我会给你例子==>

    以下是代码 -->Onclick 图片 -->Dialog Appears==>

        Dialog dialog; //your dialog declaration
         // 
        //
        //
        oncreate(){
    
    
        imageView = (ImageView) findViewById(R.id.customProfileGridImg);
        dialog = new Dialog(this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.activity);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams wlp = window.getAttributes();
    
        wlp.gravity = Gravity.START |Gravity.TOP; //change direction as per your requirement
        wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
        window.setAttributes(wlp);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.show();
    
            }
        });
        }
    

    【讨论】:

      猜你喜欢
      • 2014-04-08
      • 1970-01-01
      • 2017-02-16
      • 1970-01-01
      • 2016-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-31
      相关资源
      最近更新 更多