跟 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());