android systemui panelbar 位置显示

在划动屏幕显示statusbar时,会根据每次划动的位置不一样,下拉出的panelbar显示的位置也不一样,有时候会出现Pannelbar显示到屏幕外面的情况,控制显示位置的函数:

android/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java

private void updateVerticalPanelPosition(float x) {
       if (mNotificationStackScroller.getWidth() * 1.75f > getWidth()) {
           resetVerticalPanelPosition();
            return;
       }
        float leftMost = mPositionMinSideMargin + mNotificationStackScroller.getWidth() / 2;
        float rightMost = getWidth() - mPositionMinSideMargin
                - mNotificationStackScroller.getWidth() / 2;
        if (Math.abs(x - getWidth() / 2) < mNotificationStackScroller.getWidth() / 4) {
            x = getWidth() / 2;
        }
        x = Math.min(rightMost, Math.max(leftMost, x));
  
        float translation = x -(mNotificationStackScroller.getLeft() + mNotificationStackScroller.getWidth() / 2);
        if ((translation < 0) && (translation + mNotificationStackScroller.getLeft() < 0)) {
            setVerticalPanelTranslation(0f);
        } else {
            setVerticalPanelTranslation(translation);
        }
     }


private void setVerticalPanelTranslation(float translation) {
        mNotificationStackScroller.setTranslationX(translation);
        mScrollView.setTranslationX(translation);
        mHeader.setTranslationX(translation);

可以通过控制tanslation的值来控制pannelbar在X方向的位置。

猜你喜欢

转载自blog.csdn.net/toove/article/details/78919558
今日推荐