美文网首页
音量弹框 背景有锯齿不够丝滑

音量弹框 背景有锯齿不够丝滑

作者: gale_小米 | 来源:发表于2024-09-25 11:40 被阅读0次
image.png

处理方式1:自定义背景替换掉原本背景框

Index: frameworks/base/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java
===================================================================
@@ -634,8 +634,8 @@
     }
 
     private boolean isLandscape() {
-        return mContext.getResources().getConfiguration().orientation ==
-                Configuration.ORIENTATION_LANDSCAPE;
+        // return false;
+        return mContext.getResources().getConfiguration().orientation ==Configuration.ORIENTATION_LANDSCAPE;
     }
 
     private boolean isRtl() {
@@ -2038,7 +2038,7 @@
         background.setLayerSize(0, mDialogWidth,
                 !isLandscape()
                         ? mDialogRowsView.getHeight()
-                        : mDialogRowsView.getHeight() + mDialogCornerRadius);
+                        : mDialogRowsView.getHeight() +mDialogCornerRadius);
         // Inset the top so that the color only renders below the ringer drawer, which has its own
         // background. In landscape, reduce the inset slightly since we are using the background to
         // fill in the corners of the closed ringer drawer.
@@ -2045,7 +2045,7 @@
         background.setLayerInsetTop(0,
                 !isLandscape()
                         ? mDialogRowsViewContainer.getTop()
-                        : mDialogRowsViewContainer.getTop() - mDialogCornerRadius);
+                        : mDialogRowsViewContainer.getTop()- mDialogCornerRadius); 
 
         // Set gravity to top-right, since additional rows will be added on the left.
         background.setLayerGravity(0, Gravity.TOP | Gravity.RIGHT);
@@ -2063,9 +2063,10 @@
                 }
             });
             mRingerAndDrawerContainer.setClipToOutline(true);
+            mTopContainer.setBackgroundResource(R.drawable.volume_drawer_land_bg);
+        }else {
+            mTopContainer.setBackground(background);
         }
-
-        mTopContainer.setBackground(background);
     }
 
     private final VolumeDialogController.Callbacks mControllerCallbackH

绘制背景

Index: frameworks/base/packages/SystemUI/res/drawable/volume_drawer_land_bg.xml
===================================================================
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2021 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License
+  -->
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
+   <!-- 主体部分 -->
+    <item>
+        <shape android:shape="rectangle">
+            <solid android:color="@android:color/transparent"/> <!-- 红色 -->
+            <size android:width="@dimen/volume_dialog_panel_width" />
+        </shape>
+    </item>
+    <item
+        android:left="@dimen/volume_dialog_panel_width">
+        <shape>
+            <size android:width="@dimen/volume_dialog_panel_width" />
+            <solid android:color="?androidprv:attr/colorSurface" />
+            <corners android:radius="@dimen/volume_dialog_panel_width_half"/>
+        </shape>
+    </item>
+</layer-list>

相关文章

网友评论

      本文标题:音量弹框 背景有锯齿不够丝滑

      本文链接:https://www.haomeiwen.com/subject/wwscrjtx.html