2013-02-04 36 views
0

我想在我的项目中建立快速行动。当我点击视图时,它会正确显示弹出窗口。但没有显示指向父视图的箭头(向上箭头,向下箭头)。我尝试过很多方法。如果有一个人有更好的解决办法还是不错的逻辑,请帮我 感谢: 在这里你可以看到代码:显示自定义QuickAction弹出窗口在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()); 
     } 

和showArrow方法为:

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

与你分享xml文件。 –

回答

0

没有什么错你代码。可能有些东西在您的xml文件中会出错。请检查你的XML文件。尝试修改你的XML文件。希望你的问题得到解决。