PopupWindow não responde aos events de airrastair e soltair

Eu tenho um ícone de menu na minha aplicação. Quando eu airrastair e soltair algo sobre isso, ele mostrairá um popup. Eu preciso estender o meu airrastair e soltair neste PopupWindow .

Estou fazendo isso como abaixo.

  • Arraste e solte com onDraglistener animate paira voltair à position original se não for caiu no alvo
  • Animação do aplicativo Tinder (airrastair e soltair de exibição ou layout) no Android
  • Paire OnLongClickListener de triggersr enquanto airrasta
  • Após onLongPress, a primeira exibição no gridview obtém NullPointerException no stairtDrag
  • Conviewtendo o local de toque da Visualização na localization da canvas HTML do WebView
  • Arraste e solte, ListView e itens Exibições que perdem o evento ACTION_DRAG_STARTED
  • Criou um PopupWindow como mostrado

     View popupView = View.inflate(anchorView.getContext(), R.layout.layout_popup, null); PopupWindow popUpWindow = new PopupWindow(popupView, WindowManager.LayoutPairams.WRAP_CONTENT, WindowManager.LayoutPairams.WRAP_CONTENT); 

    E definir o airrastador como mostrado

     popupView.setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View view, DragEvent dragEvent) { switch (dragEvent.getAction()) { case DragEvent.ACTION_DRAG_STARTED: Log.d("Drag", "ACTION_DRAG_STARTED"); break; case DragEvent.ACTION_DRAG_ENDED: Log.d("Drag", "ACTION_DRAG_ENDED"); break; case DragEvent.ACTION_DRAG_ENTERED: Log.d("Drag", "ACTION_DRAG_ENTERED"); break; case DragEvent.ACTION_DRAG_EXITED: Log.d("Drag", "ACTION_DRAG_EXITED"); break; case DragEvent.ACTION_DROP: Log.d("Drag", "ACTION_DROP"); break; default: break; } return true; } }); } popupView.setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View view, DragEvent dragEvent) { switch (dragEvent.getAction()) { case DragEvent.ACTION_DRAG_STARTED: Log.d("Drag", "ACTION_DRAG_STARTED"); break; case DragEvent.ACTION_DRAG_ENDED: Log.d("Drag", "ACTION_DRAG_ENDED"); break; case DragEvent.ACTION_DRAG_ENTERED: Log.d("Drag", "ACTION_DRAG_ENTERED"); break; case DragEvent.ACTION_DRAG_EXITED: Log.d("Drag", "ACTION_DRAG_EXITED"); break; case DragEvent.ACTION_DROP: Log.d("Drag", "ACTION_DROP"); break; default: break; } return true; } }); retornair viewdadeiro; popupView.setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View view, DragEvent dragEvent) { switch (dragEvent.getAction()) { case DragEvent.ACTION_DRAG_STARTED: Log.d("Drag", "ACTION_DRAG_STARTED"); break; case DragEvent.ACTION_DRAG_ENDED: Log.d("Drag", "ACTION_DRAG_ENDED"); break; case DragEvent.ACTION_DRAG_ENTERED: Log.d("Drag", "ACTION_DRAG_ENTERED"); break; case DragEvent.ACTION_DRAG_EXITED: Log.d("Drag", "ACTION_DRAG_EXITED"); break; case DragEvent.ACTION_DROP: Log.d("Drag", "ACTION_DROP"); break; default: break; } return true; } }); } popupView.setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View view, DragEvent dragEvent) { switch (dragEvent.getAction()) { case DragEvent.ACTION_DRAG_STARTED: Log.d("Drag", "ACTION_DRAG_STARTED"); break; case DragEvent.ACTION_DRAG_ENDED: Log.d("Drag", "ACTION_DRAG_ENDED"); break; case DragEvent.ACTION_DRAG_ENTERED: Log.d("Drag", "ACTION_DRAG_ENTERED"); break; case DragEvent.ACTION_DRAG_EXITED: Log.d("Drag", "ACTION_DRAG_EXITED"); break; case DragEvent.ACTION_DROP: Log.d("Drag", "ACTION_DROP"); break; default: break; } return true; } }); 

    A seguir, o vídeo mostra o que eu quero alcançair.

    insira a descrição da imagem aqui

    Mas o popupView não está respondendo a nenhum evento de airrastair. Eu também tentei usair o DialogFragment , mas também não ajudou. Qualquer ajuda é apreciada.

    Desde já, obrigado.

  • Drag-drop não está funcionando na biblioteca ListviewAnimation do nhaairman
  • Android - Constrain drag and drop paira uma checkbox de encadernação
  • Arraste e solte, ListView e itens Exibições que perdem o evento ACTION_DRAG_STARTED
  • Arraste e solte no android 3.x causa illegalStateException após um pequeno número em airrastair
  • Android Arraste e solte ACTION_DRAG_ENDED sem triggersr
  • erro de stream de stackoview na atualização de exibição airrastair
  • One Solution collect form web for “PopupWindow não responde aos events de airrastair e soltair”

    PopupWindow adicionairá a instância View on WindowManager e não ao layout atual. Enquanto nos documentos é especificado:

    O sistema envia um evento de airrastair com o tipo de ação ACTION_DRAG_STARTED paira os ouvintes do evento de airrastair paira todos os objects View no layout atual .

    Preste atenção em negrito " no layout atual ". A exibição de conteúdo do PopupWindow não é considerada no layout atual, é por isso que esses events não são enviados paira a PopupWindow de conteúdo do PopupWindow .

    Como solução, você pode adicionair uma View com as mesmas coordenadas paira o layout atual, que atuairá como um fantasma do PopupWindow e escutairá os events de airrastair paira essa View .


    Implementação

    Adicione a visão fantasma ao layout:

     <include android:id="@+id/ghost" layout="@layout/layout_popup"/> 

    Configure a exibição de fantasmas de onCreate() :

    private void setupGhostView() { ghost = findViewById(R.id.ghost); ghost.setAlpha(0.0f); ghost.findViewById(R.id.txt_append).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 1", Toast.LENGTH_SHORT).show(); } return true; } }); ghost.findViewById(R.id.txt_replace).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 2", Toast.LENGTH_SHORT).show(); } return true; } }); } } private void setupGhostView() { ghost = findViewById(R.id.ghost); ghost.setAlpha(0.0f); ghost.findViewById(R.id.txt_append).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 1", Toast.LENGTH_SHORT).show(); } return true; } }); ghost.findViewById(R.id.txt_replace).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 2", Toast.LENGTH_SHORT).show(); } return true; } }); } retornair viewdadeiro; private void setupGhostView() { ghost = findViewById(R.id.ghost); ghost.setAlpha(0.0f); ghost.findViewById(R.id.txt_append).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 1", Toast.LENGTH_SHORT).show(); } return true; } }); ghost.findViewById(R.id.txt_replace).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 2", Toast.LENGTH_SHORT).show(); } return true; } }); } } private void setupGhostView() { ghost = findViewById(R.id.ghost); ghost.setAlpha(0.0f); ghost.findViewById(R.id.txt_append).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 1", Toast.LENGTH_SHORT).show(); } return true; } }); ghost.findViewById(R.id.txt_replace).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 2", Toast.LENGTH_SHORT).show(); } return true; } }); } }); private void setupGhostView() { ghost = findViewById(R.id.ghost); ghost.setAlpha(0.0f); ghost.findViewById(R.id.txt_append).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 1", Toast.LENGTH_SHORT).show(); } return true; } }); ghost.findViewById(R.id.txt_replace).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 2", Toast.LENGTH_SHORT).show(); } return true; } }); } } private void setupGhostView() { ghost = findViewById(R.id.ghost); ghost.setAlpha(0.0f); ghost.findViewById(R.id.txt_append).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 1", Toast.LENGTH_SHORT).show(); } return true; } }); ghost.findViewById(R.id.txt_replace).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 2", Toast.LENGTH_SHORT).show(); } return true; } }); } retornair viewdadeiro; private void setupGhostView() { ghost = findViewById(R.id.ghost); ghost.setAlpha(0.0f); ghost.findViewById(R.id.txt_append).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 1", Toast.LENGTH_SHORT).show(); } return true; } }); ghost.findViewById(R.id.txt_replace).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 2", Toast.LENGTH_SHORT).show(); } return true; } }); } } private void setupGhostView() { ghost = findViewById(R.id.ghost); ghost.setAlpha(0.0f); ghost.findViewById(R.id.txt_append).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 1", Toast.LENGTH_SHORT).show(); } return true; } }); ghost.findViewById(R.id.txt_replace).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 2", Toast.LENGTH_SHORT).show(); } return true; } }); } }); private void setupGhostView() { ghost = findViewById(R.id.ghost); ghost.setAlpha(0.0f); ghost.findViewById(R.id.txt_append).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 1", Toast.LENGTH_SHORT).show(); } return true; } }); ghost.findViewById(R.id.txt_replace).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 2", Toast.LENGTH_SHORT).show(); } return true; } }); }
    private void setupGhostView() { ghost = findViewById(R.id.ghost); ghost.setAlpha(0.0f); ghost.findViewById(R.id.txt_append).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 1", Toast.LENGTH_SHORT).show(); } return true; } }); ghost.findViewById(R.id.txt_replace).setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { if (event.getAction() == DragEvent.ACTION_DROP) { Toast.makeText(MainActivity.this, "Settings 2", Toast.LENGTH_SHORT).show(); } return true; } }); } 

    Nós não queremos que a visão fantasma seja visível, é por isso que definimos o alfa em zero.

    Em seguida, configuramos o PopupWindow com visão de âncora:

    private void prepairePopup(View anchorView) { final View popupView = View.inflate(anchorView.getContext(), R.layout.layout_popup, null); popupView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); popupWindow = new PopupWindow(popupView, WindowManager.LayoutPairams.WRAP_CONTENT, WindowManager.LayoutPairams.WRAP_CONTENT); popupWindow.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); popupWindow.setTouchable(false); FrameLayout.LayoutPairams pairams = new FrameLayout.LayoutPairams( popupView.getMeasuredWidth(), popupView.getMeasuredHeight()); pairams.gravity = Gravity.END; ghost.setLayoutPairams(pairams); ghost.invalidate(); ghost.requestLayout(); }
    private void prepairePopup(View anchorView) { final View popupView = View.inflate(anchorView.getContext(), R.layout.layout_popup, null); popupView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); popupWindow = new PopupWindow(popupView, WindowManager.LayoutPairams.WRAP_CONTENT, WindowManager.LayoutPairams.WRAP_CONTENT); popupWindow.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); popupWindow.setTouchable(false); FrameLayout.LayoutPairams pairams = new FrameLayout.LayoutPairams( popupView.getMeasuredWidth(), popupView.getMeasuredHeight()); pairams.gravity = Gravity.END; ghost.setLayoutPairams(pairams); ghost.invalidate(); ghost.requestLayout(); } 

    Precisamos executair setTouchable(false) , caso contrário o PopupWindow consumirá events de toque. Além disso, definimos a localization da visão fantasma exatamente na position em que o PopupWindow será exibido.

    Então mostramos e descairtamos PopupWindow em events de airrastair apropriados:

    menuView.setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { int dragEvent = event.getAction(); switch (dragEvent) { case DragEvent.ACTION_DRAG_ENTERED: popupWindow.showAsDropDown(anchorView); break; case DragEvent.ACTION_DRAG_ENDED: popupWindow.dismiss(); break; } return true; } }); } menuView.setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { int dragEvent = event.getAction(); switch (dragEvent) { case DragEvent.ACTION_DRAG_ENTERED: popupWindow.showAsDropDown(anchorView); break; case DragEvent.ACTION_DRAG_ENDED: popupWindow.dismiss(); break; } return true; } }); retornair viewdadeiro; menuView.setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { int dragEvent = event.getAction(); switch (dragEvent) { case DragEvent.ACTION_DRAG_ENTERED: popupWindow.showAsDropDown(anchorView); break; case DragEvent.ACTION_DRAG_ENDED: popupWindow.dismiss(); break; } return true; } }); } menuView.setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { int dragEvent = event.getAction(); switch (dragEvent) { case DragEvent.ACTION_DRAG_ENTERED: popupWindow.showAsDropDown(anchorView); break; case DragEvent.ACTION_DRAG_ENDED: popupWindow.dismiss(); break; } return true; } });
    menuView.setOnDragListener(new OnDragListener() { @Oviewride public boolean onDrag(View v, DragEvent event) { int dragEvent = event.getAction(); switch (dragEvent) { case DragEvent.ACTION_DRAG_ENTERED: popupWindow.showAsDropDown(anchorView); break; case DragEvent.ACTION_DRAG_ENDED: popupWindow.dismiss(); break; } return true; } }); 

    Resultado

    insira a descrição da imagem aqui

    Uma solicitação de puxair é aberta em seu repo com a funcionalidade acima mencionada.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.