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

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>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 27,646评论 1 45
  • 前言 终于在周末抽出时间来整理了一下有关文字边框/背景效果的代码,之前在写这个效果的时候也是经历了很多坎坷。在前期...
    沙琪玛dd阅读 6,541评论 7 24
  • 用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你...
    hw1212阅读 12,885评论 2 59
  • [TOC] 1 JAVA: String为什么这么设计 在源码中string是用final 进行修饰,它是不可更改...
    寄浮生阅读 860评论 0 0
  • OC语言基础 1.类与对象 类方法 OC的类方法只有2种:静态方法和实例方法两种 在OC中,只要方法声明在@int...
    奇异果好补阅读 4,348评论 0 11