Android裏把Dialog設置爲全屏的方法

                                         Android裏把Dialog設置爲全屏的方法

 有的時候我們需要把Dialog設置爲全屏,於是我們想到了如下的辦法:

//設置成全屏
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
mDetailDialog.addContentView(detailView, p);

 實際情況是dialog根本不會全屏,正確方法如下:

private PasswordOrAskSen5Dialog mDetailDialog = null;
LayoutInflater layoutInflater = LayoutInflater.from(mContext);

//dialog 裏要顯示的內容view
View detailView = layoutInflater.inflate(R.layout.channel_bar_epg_detail, null);

//需根據實際情況創建你的Dialog
mDetailDialog = new Dialog();

//設置成全屏
Display display = mDetailDialog.getWindow().getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(width, height);
mDetailDialog.addContentView(detailView, p);

Window window = mDetailDialog.getWindow();
WindowManager.LayoutParams attributes = window.getAttributes();
attributes.alpha = DVBSApplication.mClientPreferences.getFloat(ContactsUtil.PREFERENCES_VIEW_ALPHA, ContactsUtil.DEFAULT_VIEW_ALPHA);
attributes.gravity = Gravity.LEFT | Gravity.BOTTOM;
mDetailDialog.onWindowAttributesChanged(attributes);

if (!mDetailDialog.isShowing()) {
    mDetailDialog.show();

    //設置滑出來的動畫效果
    detailView.post(new Runnable() {
        @Override
        public void run() {
            float TranslationY = detailView.getTranslationY();
            float start_position = TranslationY + detailView.getHeight();
            ObjectAnimator transAnim1 = ObjectAnimator.ofFloat(detailView, "translationY", start_position, TranslationY);
            transAnim1.setInterpolator(new AccelerateInterpolator());
            transAnim1.setDuration(500);
            transAnim1.start();
        }
    });
} else {
    DLog.d("askDialogSen5.isShowing  !!!  cann't show this");
}

                                                                                  THE         END

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章