动态设置DiaLog高度

/**
 * 设置 dialog的高度
 * 可根据list的条数来设置高度
 * @param dialog
 */
private void setDialogHeight(List list, AlertDialog dialog) {
    WindowManager m = getWindowManager();
    Display display = m.getDefaultDisplay();
    WindowManager.LayoutParams p = dialog.getWindow().getAttributes();  //获取对话框当前的参数值
    if (list.size() > 5) p.height = (int) (display.getHeight() * 0.5);//设置为当前屏幕高度的一半
    if (list.size() <= 5) p.height = RecyclerView.LayoutParams.WRAP_CONTENT;
    dialog.getWindow().setAttributes(p);     //设置生效
}

 

猜你喜欢

转载自blog.csdn.net/GodnessIsMyMine/article/details/81976505
今日推荐