2

I'm trying to locate my dialog in a specific location on screen. Here is my dialog implementation :

public class DayDialog extends android.support.v4.app.DialogFragment {
public static DayDialog newInstance() {
    DayDialog f = new DayDialog();
    f.setCancelable(true);
    f.setStyle(STYLE_NO_TITLE, 0);
    return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View layout = inflater.inflate(R.layout.dialog_calendar_day, container);
    WindowManager.LayoutParams params = getDialog().getWindow()
            .getAttributes();
    params.gravity = Gravity.TOP | Gravity.LEFT;
    params.x = 0;//b.getInt("x");
    params.y = 0;//b.getInt("y");
    getDialog().getWindow().setAttributes(params);
    return layout;
}

here is how my dialog shown! how can I locate it (0,0) ? it's like there is a frame or something around it!

screenshot

Jonik
  • 80,077
  • 70
  • 264
  • 372
Mohammad Rahchamani
  • 5,002
  • 1
  • 26
  • 36

1 Answers1

2

There is fact a frame around it, that is defined in styles.xml, more specific it's the this 9-patch. The way i see it you have two options:

  1. Start playing around with negative top/left margin params until you align it exactly where you want it (watch out to use dpi values).
  2. Apply the DialogFragment.STYLE_NO_FRAME like so:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);       
        setStyle(DialogFragment.STYLE_NO_FRAME, 0);
    }
    
Lena Bru
  • 13,521
  • 11
  • 61
  • 126
4spins
  • 144
  • 2
  • 3