DialogFragment在Android的位置 [英] Position of DialogFragment in Android

查看:1066
本文介绍了DialogFragment在Android的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 DialogFragment 来显示查看就像一个弹出式屏幕。 窗口总是出现在屏幕的中间。 有没有一种方法来设置 DialogFragment 窗口的位置? 我特地到<一个href="http://pop3.amvg.com/owa/redir.aspx?C=643d6366070c4d70b56ecc52543c4f58&URL=http://$c$c.google.com/p/android-eksempler/source/browse/trunk/Android30Elementer/assets/src/android/support/v4/app/">source code 也没有找到任何东西。

I have a DialogFragment to show a View like a Popup screen. The Window appears always in the middle of the screen. Is there a way to set the position of the DialogFragment window? I have looked in to the source code but couldn't find anything yet.

推荐答案

尝试是这样的:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    getDialog().getWindow().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
    WindowManager.LayoutParams p = getDialog().getWindow().getAttributes();
    p.width = ViewGroup.LayoutParams.MATCH_PARENT;
    p.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE;
    p.x = 200;
    ...
    getDialog().getWindow().setAttributes(p);
    ...

或其他方法 getDialog()。getWindow()

要在调用设置的内容后设置的位置。

be sure to set the position after calling set-content.

这篇关于DialogFragment在Android的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆