android systemui panelbar 位置显示

在Android中,当滑动显示statusbar时,PanelBar的位置会根据滑动位置变化。有时PanelBar可能会超出屏幕。关键代码位于`NotificationPanelView`类中的`updateVerticalPanelPosition`和`setVerticalPanelTranslation`方法,通过调整translation值来控制PanelBar在X轴的位置,防止其显示在屏幕外。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在划动屏幕显示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方向的位置。

SwipePanel(侧划控件)Background对市面上实现的侧划返回不是很满意(仿微信,QQ 通过修改窗口透明坑太多),最终决定还是亲手写一个高实用性的吧,效果如下所示,换个图标,更多划动功能可以由你自己解锁,总共一个 600 多行代码的类,推荐通过阅读源码,你肯定会收获很多哈。Preview DownloadGradle:implementation 'com.blankj:swipe-panel:1.0'How to use动态final SwipePanel swipePanel = new SwipePanel(this); swipePanel.setLeftEdgeSize(SizeUtils.dp2px(100));// 设置左侧触发阈值 100dp swipePanel.setLeftDrawable(R.drawable.base_back);// 设置左侧 icon swipePanel.wrapView(findViewById(R.id.rootLayout));// 设置嵌套在 rootLayout 外层 swipePanel.setOnFullSwipeListener(new SwipePanel.OnFullSwipeListener() {// 设置完全划开松手后的监听     @Override     public void onFullSwipe(int direction) {         finish();         swipePanel.close(direction);// 关闭     } });静态<com.blankj.swipepanel.SwipePanel         xmlns:android="http://schemas.android.com/apk/res/android"         xmlns:tools="http://schemas.android.com/tools"         xmlns:app="http://schemas.android.com/apk/res-auto"         android:id="@ id/swipePanel"         android:background="@color/mediumGray"         android:layout_width="match_parent"         android:layout_height="match_parent"         tools:context=".LayoutSwipePanelActivity"         app:isLeftCenter="false"         app:leftEdgeSize="100dp"         app:leftSwipeColor="@color/colorPrimary"         app:leftDrawable="@drawable/base_back">     ... </com.blankj.swipepanel.SwipePanel>API方法名属性名说明setLeft(Top, Right, Bottom)SwipeColorapp:left(top, right, bottom)SwipeColor设置左(上、右、下)测颜色setLeft(Top, Right, Bottom)EdgeSizeapp:left(top, right, bottom)EdgeSize设置左(上、右、下)测触发阈值setLeft(Top, Right, Bottom)Drawableapp:left(top, right, bottom)Drawable设置左(上、右、下)测 iconsetLeft(Top, Right, Bottom)Centerapp:isLeft(Top, Right, Bottom)Center设置左(上、右、下)测是否居中setLeft(Top, Right, Bottom)Enabledapp:isLeft(Top, Right, Bottom)Enabled设置左(上、右、下)测是否可用wrapView---设置嵌套在该 view 的外层setOnFullSwipeListener---设置完全划开松手后的监听isOpen---判断是否被划开close---关闭
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值