I want to display a popup window in my code such that, no matter where I touch on the screen, the popup should show up right above the place I touch. Not sure, how to achieve this. This is my current popup window code:
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View customView = inflater.inflate(R.layout.popup,null);
final PopupWindow popupWindow = new PopupWindow(
customView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
// Set an elevation value for popup window
// Call requires API level 21
if(Build.VERSION.SDK_INT>=21){
popupWindow.setElevation(5.0f);
}
final TextView placename = (TextView) customView.findViewById(R.id.popup_id) ;
Button closeButton = (Button) customView.findViewById(R.id.directions);
placename.setText(place.getName());
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setOutsideTouchable(true);
// Set a click listener for the popup window close button
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Dismiss the popup window
popupWindow.dismiss();
}
});
popupWindow.setFocusable(true);
popupWindow.showAtLocation(mapInsideContainer, Gravity.CENTER, 0, 0);
popupWindow.showAsDropDown(customView);
This is my popup.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@android:color/background_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="1dp"
android:background="@android:color/white">
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="20dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:id="@+id/popup_id" />
<Button
android:id="@+id/directions"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/black_overlay"
android:textColor="@android:color/white"
android:text="Directions" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Currently it shows on the center of the screen due to Gravity.CENTER, but I would like to show it right above the place I touch dynamically on screen. Any ideas? Thanks
Bonus points if you could guide me through creating a chat bubble like popup with title on top and a "places" button at the bottom with the bubble pointer at the position clicked on screen