I am writing my first android program and am having difficulty placing PopupWindow and size, as I assume. Since at the moment the popup will be activated after clicking the button in the menu bar. After clicking, I was hoping that the pop-up display would be centralized, however, currently clicking on the result displays the image below (cannot send the image due to reputation 10):
https://www.box.com/s/7d4qk8tqlvhiog7576mc
Java Popup Method and Listener:
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; } }
}
Add Xml Layout:
<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"> <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"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/holo_blue_bright"/> <EditText android:id="@+id/task_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/task_prompt"> </EditText> </LinearLayout>
Any help would be greatly appreciated.
source share