0

I'm using the following code inside my DialogFragment.onCreateView() to set its gravity on top:

Window window = getDialog().getWindow();
window.setGravity(Gravity.TOP);

This works perfectly on newer Android API versions but not on phones/emulators using Gingerbread (API 9 or 10). I also tried to use the following code on onViewCreated() without success:

View v = getDialog().getWindow().getDecorView();
WindowManager.LayoutParams lp = (WindowManager.LayoutParams)v.getLayoutParams();
lp.gravity = Gravity.TOP;
getActivity().getWindowManager().updateViewLayout(v, lp);

Any suggestions?

Ricardo
  • 7,785
  • 8
  • 40
  • 60

1 Answers1

1

try this

WindowManager.LayoutParams lp = (WindowManager.LayoutParams)v.getLayoutParams();
lp.y = -200;
lp.x= -200;
getActivity().getWindowManager().updateViewLayout(v, lp);

change the value of lp.x and lp.y as per your requirment

Raju Sen
  • 61
  • 4
  • Doesn't work, sorry. But it was a good workaround to try. Also you made me see by debugging it that `onViewCreated()` is actually not called at all on a `DialogFragment`. See this: http://stackoverflow.com/questions/10594992/android-dialogfragment-onviewcreated-not-called – Ricardo Jan 22 '14 at 11:49