Positon an Acitvity applied with a theme dialog at a particular x, y position

假装没事ソ 提交于 2019-12-01 09:38:04

This is the code!

LayoutParams lp = this.getWindow().getAttributes();
             lp.x=50;lp.y=20;lp.width=100;lp.height=200;lp.gravity=Gravity.TOP | Gravity.LEFT;
            lp.dimAmount=0;            
            lp.flags=LayoutParams.FLAG_LAYOUT_NO_LIMITS | LayoutParams.FLAG_NOT_TOUCH_MODAL;
this.setContentView(view, lp);

Don't extend the dialog theme extend the panel theme.

<style name="Theme.CustomPanel" parent="@android:style/Theme.Panel">        
         <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
         <item name="android:backgroundDimEnabled">true</item>
    </style>

This creates a window similar to a dialog except it doesn't center it like a dialog does. Then create an activity like you normally would then start it.

To make it 5px from left and 10px from top just put padding on your layout

 <!-- res/layout/your_layout.xml -->
   <FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:paddingTop="10px"
  android:paddingLeft="5px"></FrameLayout>

And of course your activity should just be normal like

public class NonCenteredDialogActivity extends Activity{
      protected void onCreate(Bundle bundle){
          super.onCreate(bundle);
          setContentView(R.layout.your_layout);
      }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!