0

我已经尝试在滑动菜单中使用选择器 2 天了,但没有成功。

这是我想做的:

我有一个菜单,里面有一个 ListView。我希望选择器指向一个特定的项目并在滚动列表视图时随项目一起移动。

所以基本上选择器指向正确的项目,但是当我滚动时,选择器不会在我的手机(android 4.0.4)上移动,但它适用于模拟器(4.1.2)。当我要求他这样做时,您知道为什么菜单没有自行失效吗?

    /*Setting the sliding menu */  

        setBehindContentView(R.layout.menu);
        setSlidingActionBarEnabled(true);      



        getSlidingMenu().setMode(SlidingMenu.LEFT);
        getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

        getSlidingMenu().setFadeEnabled(true);
        getSlidingMenu().setFadeDegree(0.35f);
        getSlidingMenu().setShadowWidth(15);
        getSlidingMenu().setShadowDrawable(R.drawable.shadow);
        getSlidingMenu().setSelectorEnabled(true);
        getSlidingMenu().setSelectorDrawable(R.drawable.selector);

        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);

        getSlidingMenu().setBehindWidth((int) (metrics.widthPixels * 0.8));
        getSlidingMenu().setSelectedView(null);

        /*Creating the content of the sliding menu*/

                    /*Now we generate the menu below */
        maListViewPerso = (ListView) this.findViewById(R.id.listviewperso);

        maListViewPerso = SlidingMenuListCreator.getListView(this, (String) this.getTitle(), maListViewPerso, isMissionSelected, isTourneeOpened);

        getSlidingMenu().setOnOpenListener(new OnOpenListener() {

            @Override
            public void onOpen() {

                                    int wantedPosition = 5; // Whatever position you're looking for
                int firstPosition = maListViewPerso.getFirstVisiblePosition() - maListViewPerso.getHeaderViewsCount();                  int wantedChild = wantedPosition - firstPosition;
                                    if (wantedChild < 0 || wantedChild >= maListViewPerso.getChildCount()) {
                                        } else {
                    selectedView = maListViewPerso.getChildAt(wantedChild);
                                        }

                getSlidingMenu().setSelectedView(selectedView);
                getSlidingMenu().invalidate();



            }
        });

        OnTouchListener mOnTouchListener = new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {


                maListViewPerso.onTouchEvent(event);

                int wantedPosition = 5;                 int firstPosition = maListViewPerso.getFirstVisiblePosition() - maListViewPerso.getHeaderViewsCount();                  int wantedChild = wantedPosition - firstPosition;
                                    if (wantedChild < 0 || wantedChild >= maListViewPerso.getChildCount()) {

                } else {
                    selectedView = maListViewPerso.getChildAt(wantedChild);                 }

                getSlidingMenu().setSelectedView(selectedView);
                getSlidingMenu().getmViewBehind().invalidate();

                                    return true;
            }
        };

        maListViewPerso.setOnTouchListener(mOnTouchListener);
4

1 回答 1

2

毕竟我从来没有找到解决办法。

但 :

  1. 我切换到 viewpager 导航模式,因为这是用户的首选(并发现,是的,片段很棒)

  2. 谷歌终于通过支持库和抽屉布局添加了这种导航模式“官方”,它对我来说效果很好=)

于 2014-07-18T11:27:36.757 回答