0

我正在尝试在我的项目中构建快速操作。当我单击视图时,它会正确显示弹出窗口。但是指向父视图的箭头(向上箭头,向下箭头)没有显示。我在很多方面都试过了。如果有人有更好的解决方案或良好的逻辑,请帮助我谢谢:在这里你可以看到代码:

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);
    }
4

1 回答 1

0

您的代码没有任何问题。可能,您的 xml 文件中有些问题。请检查您的 xml 文件。尝试修改您的 xml 文件。希望,您的问题将得到解决。

于 2013-02-20T18:13:55.363 回答