2013-02-04 4 views
0

J'essaie de construire l'action rapide dans mon projet. quand je clique sur la vue, la fenêtre pop-up s'affiche correctement. Mais la flèche (flèche vers le haut, flèche vers le bas) qui pointe vers la vue parent n'est pas visible. Je l'ai essayé de plusieurs façons. si quelqu'un a la meilleure solution ou une bonne logique s'il vous plaît me aider grâce: Ici vous pouvez voir le code:show Fenêtre contextuelle QuickAction personnalisée dans android

public void show (View anchor) { 
     preShow(); 

     int[] location  = new int[2]; 

     anchor.getLocationOnScreen(location); 

     Rect anchorRect  = new Rect(location[0], location[1], location[0] + anchor.getWidth(), location[1] 
          + anchor.getHeight()); 

     mRootView.setLayoutParams(new LayoutParams(300, 400)); 
     mRootView.measure(200,300); 

     int rootWidth  = mRootView.getMeasuredWidth(); 
     int rootHeight  = mRootView.getMeasuredHeight(); 

     int screenWidth  = mWindowManager.getDefaultDisplay().getWidth(); 

     int xPos   = (screenWidth - rootWidth)/2; 
     int yPos   = anchorRect.top - rootHeight; 

     boolean onTop  = true; 

     if (rootHeight > anchor.getTop()) { 
      yPos = anchorRect.bottom; 
      onTop = false; 
     } 
     if(onTop==true){ 
      showArrow(R.id.arrow_down, anchorRect.centerX()); 
     } 
     else 
     { 
      showArrow(R.id.arrow_up, anchorRect.centerX()); 
     } 

et la méthode showArrow est aussi:

private void showArrow(int whichArrow, int requestedX) { 
     final View showArrow; 
     final View hideArrow; 
     if(whichArrow==R.id.arrow_down) 
     { 
      showArrow=mArrowDown; 
      hideArrow=mArrowUp; 

     } 
     else{ 
      showArrow=mArrowUp; 
      hideArrow=mArrowDown;  
     } 


     final int arrowWidth = mArrowUp.getMeasuredWidth(); 

     showArrow.setVisibility(View.VISIBLE); 


     ViewGroup.MarginLayoutParams param = (ViewGroup.MarginLayoutParams)showArrow.getLayoutParams(); 

     param.leftMargin = requestedX - arrowWidth/2; 

     hideArrow.setVisibility(View.INVISIBLE); 
    } 
+0

partagez votre fichier XML. –

Répondre

0

Il n'y a rien de mal avec vous code.Probablement, quelque chose ne va pas dans votre fichier XML. S'il vous plaît examiner votre fichier XML. Essayez de modifier votre fichier XML. J'espère que votre problème sera résolu.

Questions connexes