Je veux afficher une fenêtre contextuelle dans mon code de sorte que, peu importe où je touche sur l'écran, la fenêtre apparaisse juste au-dessus de l'endroit où je touche . Pas sûr, comment y parvenir. Ceci est mon code actuel de fenêtre:Comment afficher une fenêtre popup juste au-dessus de l'endroit où j'ai touché l'écran
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);
Ceci est mon 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>
Actuellement, il montre au centre de l'écran en raison de Gravity.CENTER, mais je voudrais montrer juste au-dessus de l'endroit où je touche dynamiquement à l'écran. Des idées? Merci
points bonus si vous pouviez me guider à travers la création d'une bulle de chat comme pop-up avec le titre sur le dessus et un bouton « endroits » en bas avec le pointeur de la bulle à la position cliqué sur l'écran
si vous pouvez aider avec des détails qui seront utiles que l'activité transparente partie est source de confusion et je ne sais pas comment cela pourrait résoudre le problème de fenêtre ne pas afficher à droite au-dessus du point de toucher –
@JusticeBauer J'ai édité ma réponse pour fournir quelques détails. Je vais éditer plus ce soir mais je dois y aller maintenant. –
@JusticeBauer J'ai ajouté plus de détails. –