窗口样式的activity显示位置

activity显示成窗口样式后,默认是显示在中间,但是想要实现显示在任意位置,方法如下:


 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  //关键代码
  WindowManager.LayoutParams lp = getWindow().getAttributes();
  lp.width = LayoutParams.FILL_PARENT;
  lp.gravity = Gravity.TOP;
  getWindow().setAttributes(lp);
 }

这样activity就在屏幕的顶部显示了。

你可能感兴趣的:(窗口样式的activity显示位置)