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

十三邵 2014-08-18 01:08:26
在A activity中按钮B后弹出 C activity,C是以Dialog形式弹出的,但是弹出后是居中的,请问如何修改?重修dialog的话设置什么属性能不居中?
...全文
512 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Linky1990 2015-04-23
  • 打赏
  • 举报
回复
只加这句 getWindow().getAttributes().gravity = Gravity.RIGHT; 即可, getWindow().getAttributes().width = LayoutParams.WRAP_CONTENT; 可以省略
Darcy杨 2014-08-18
  • 打赏
  • 举报
回复
刚好做过而已
十三邵 2014-08-18
  • 打赏
  • 举报
回复
引用 6 楼 youngc527 的回复:
那就更省事儿了
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().getAttributes().width = LayoutParams.WRAP_CONTENT;
		getWindow().getAttributes().gravity = Gravity.RIGHT;
	}
大神给跪了,太NB了,我查了一下午的问题让你轻松解决了!
Darcy杨 2014-08-18
  • 打赏
  • 举报
回复
那就更省事儿了
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().getAttributes().width = LayoutParams.WRAP_CONTENT;
		getWindow().getAttributes().gravity = Gravity.RIGHT;
	}
十三邵 2014-08-18
  • 打赏
  • 举报
回复
引用 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启动的,没办法用你那个方法啊?
Darcy杨 2014-08-18
  • 打赏
  • 举报
回复
		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;
			}
		}
十三邵 2014-08-18
  • 打赏
  • 举报
回复
C Activity实在声明文件中声明为android:theme="@style/FunctionDialog" ,不知道设置什么属性可以让C Activity不居中而局右
十三邵 2014-08-18
  • 打赏
  • 举报
回复
引用 1 楼 lczfriends 的回复:
自定义dialog
然后呢?
Andecy 2014-08-18
  • 打赏
  • 举报
回复
自定义dialog

80,352

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧