3

The image above is my current activity with a dialog fragment. as you can see dialog is in the middle of the screen but it want it to look something like in google maps where when I click on the button the dialog appears near the button:

enter image description here

=>

result

As you can see in google maps the dialog is not in the middle its near the selected button. This is my code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/edit_name"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:layout_gravity="center"
 android:orientation="vertical">

<TextView
    android:id="@+id/lbl_your_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Your name" />

<EditText
    android:id="@+id/txt_your_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:imeOptions="actionDone"
    android:inputType="text" />
</LinearLayout>

Which looks like this:

res4e

As you can see when I edit my dialogfragment the edittext and textview are on the top of the screen but for some reason when I deploy the app they are in the middle.

Jebemti mater
  • 124
  • 11

1 Answers1

0

Try this, it will move the dialog BOTTOM,TOP,RIGHT,LEFT.

Dialog d = <code to create custom dialog>;

Window window = d.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.BOTTOM; 
wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(wlp);

Use Gravity.TOP,BOTTOM,RIGHT,LEFT to place dialog in that position.

Navin Kumar
  • 1,940
  • 2
  • 12
  • 32