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 に答える