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

前端 未结 2 1708
情深已故
情深已故 2021-01-15 04:53

I would like to place the dialog on a particular position on the screen(-10px from top and -5px from let).

I did apply the theme and added the android:scrollX<

相关标签:
2条回答
  • 2021-01-15 05:24

    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);
    
    0 讨论(0)
  • 2021-01-15 05:26

    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);
          }
        }
    
    0 讨论(0)
提交回复
热议问题