Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set the layout and size of a PopupWindow
    text
    copied!<p>I'm writing my first program from android, and having difficulty getting a PopupWindow to be positioned and sized as I intend. As it currently is the popup will be activated after clicking a button on the menu bar. After clicking I was hoping to have the popup display centralised, however currently when clicked the result is the picture below (can't post image due to &lt;10 reputation):</p> <p><a href="https://www.box.com/s/7d4qk8tqlvhiog7576mc" rel="nofollow">https://www.box.com/s/7d4qk8tqlvhiog7576mc</a></p> <p>Java Popup Method and Listener:</p> <pre><code>public void showPopup(View add){ PopupWindow popup = new PopupWindow(this); setContentView(R.layout.add); popup.setBackgroundDrawable(null); popup.showAtLocation(add, Gravity.CENTER,0,0); popup.setFocusable(true); popup.setOutsideTouchable(true); View hideAdd = findViewById(R.id.add_task); hideAdd.setVisibility(View.INVISIBLE); } public boolean onOptionsItemSelected(MenuItem menuItem){ switch(menuItem.getItemId()){ case R.id.add_task: View addTaskView = findViewById(R.id.add_task); showPopup(addTaskView); return true; default: return false; } } </code></pre> <p>}</p> <p>Add Layout Xml:</p> <pre><code> &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal"&gt; &lt;TextView android:id="@+id/title_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/task_title" android:textSize="25sp" android:textColor="@android:color/holo_blue_bright"/&gt; &lt;View android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/holo_blue_bright"/&gt; &lt;EditText android:id="@+id/task_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/task_prompt"&gt; &lt;/EditText&gt; &lt;/LinearLayout&gt; </code></pre> <p>Any help will be greatly appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload