Android 自定义dialog出现的位置

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


转载于:https://www.cnblogs.com/guochangxin/p/11471323.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值