本文實(shí)例講述了android自由改變Dialog窗口位置的方法。分享給大家供大家參考。具體如下:
Dialog dialog = new Dialog(this);dialog.setContentView(R.layout.dialog_layout);dialog.setTitle("Custom Dialog"); //獲得當(dāng)前窗體Window window = dialog.getWindow();//重新設(shè)置WindowManager.LayoutParams lp = dialogWindow.getAttributes();window .setGravity(Gravity.LEFT | Gravity.TOP);lp.x = 100; // 新位置X坐標(biāo)lp.y = 100; // 新位置Y坐標(biāo)lp.width = 300; // 寬度lp.height = 300; // 高度lp.alpha = 0.7f; // 透明度// dialog.onWindowAttributesChanged(lp);//(當(dāng)Window的Attributes改變時(shí)系統(tǒng)會(huì)調(diào)用此函數(shù))window .setAttributes(lp);dialog.show();希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選