Avtivity以dialog形式弹出后怎么不居中而是靠右?

Android 码拜 9年前 (2015-05-10) 1359次浏览 0个评论
 

在A   activity中按钮B后弹出   C   activity,C是以Dialog形式弹出的,但是弹出后是居中的,请问如何修改?重修dialog的话设置什么属性能不居中?  

自定义dialog
引用 1 楼 lczfriends 的回复:

自定义dialog

然后呢?

C Activity实在声明文件中声明为android:theme=”@style/FunctionDialog” ,不知道设置什么属性可以让C Activity不居中而局右
		Dialog dialog = getDialog();
		Window window = dialog == null ? null : dialog.getWindow();
		if (dialog != null && window != null) {
			LayoutParams attr = window.getAttributes();
			if (attr != null) {
				attr.height = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
				attr.gravity = Gravity.RIGHT;
			}
		}
引用 4 楼 youngc527 的回复:
		Dialog dialog = getDialog();
		Window window = dialog == null ? null : dialog.getWindow();
		if (dialog != null && window != null) {
			LayoutParams attr = window.getAttributes();
			if (attr != null) {
				attr.height = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
				attr.gravity = Gravity.RIGHT;
			}
		}
		fanhui.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent function = new Intent();
				function.setClass(UserJiuGongGeActivity.this, FunctionActivity.class);
				startActivity(function);

			}
		});

dialog是Activity,是由intent启动的,没办法用你那个方法啊?

那就更省事儿了

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().getAttributes().width = LayoutParams.WRAP_CONTENT;
		getWindow().getAttributes().gravity = Gravity.RIGHT;
	}
引用 6 楼 youngc527 的回复:

那就更省事儿了

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().getAttributes().width = LayoutParams.WRAP_CONTENT;
		getWindow().getAttributes().gravity = Gravity.RIGHT;
	}

大神给跪了,太NB了,我查了一下午的问题让你轻松解决了!

40分
刚好做过而已
只加这句 getWindow().getAttributes().gravity = Gravity.RIGHT; 即可,
getWindow().getAttributes().width = LayoutParams.WRAP_CONTENT; 可以省略

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Avtivity以dialog形式弹出后怎么不居中而是靠右?
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!