MediaStyle LargeIcon的大小

ini*_*mfs 10 android android-notifications bitmapfactory android-bitmap

我正在使用新的Notification.MediaStyle类为FTP流媒体音乐播放器应用程序实现Lollipop风格的通知.我将专辑封面设为我的"大图标".

鉴于专辑封面直接取自当前正在播放的文件,此专辑封面的大小取决于来源(可能高达5000x5000).

从我的棒棒糖前代码中,我在以下定义的最大大小下解码位图: android.R.dimen.notification_large_icon_width

android.R.dimen.notification_large_icon_height

这适用于解码时间更快,内存使用是理想的.

但是,当此代码应用于我的MediaStyle样式时,展开的视图使用比尺寸参数定义的图标大得多的图标,从而在展开时产生模糊的专辑封面.

是否有一些常量来定义MediaStyle大图标的展开视图的最大大小?或者这个问题有一些解决方法吗?就目前而言,以全分辨率解码艺术是不可接受的,因为它可能导致应用程序因OOM而崩溃.

s.m*_*aks 4

从 Lollipop 源代码中我可以看到图像大小为 128dp,请参阅GitHub 上的 notification_template_material_big_media.xml

<!-- Layout to be used with only max 3 actions. It has a much larger picture at the left side-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/status_bar_latest_event_content"
    android:layout_width="match_parent"
    android:layout_height="128dp"
    android:background="#00000000"
    android:tag="bigMediaNarrow"
    >
    <ImageView android:id="@+id/icon"
        android:layout_width="128dp"
        android:layout_height="128dp"
        android:scaleType="centerCrop"
        />

    <!-- ...Nothing interesting for us futher... -->

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这是用于具有 3 个或更少操作按钮的扩展布局。查看GrepCode 上的 Notification.MediaStyle.getBigLayoutResource(int),如果有更多按钮,则似乎使用了notification_template_material_big_media.xml :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/status_bar_latest_event_content"
    android:layout_width="match_parent"
    android:layout_height="128dp"
    android:background="#00000000"
    android:tag="bigMedia"
    >
    <include layout="@layout/notification_template_icon_group"
        android:layout_width="@dimen/notification_large_icon_width"
        android:layout_height="@dimen/notification_large_icon_height"
        />

    <!-- ...Nothing interesting for us futher... -->

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

notification_template_icon_group.xml如下所示:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:internal="http://schemas.android.com/apk/prv/res/android"
    android:layout_width="@dimen/notification_large_icon_width"
    android:layout_height="@dimen/notification_large_icon_height"
    android:id="@+id/icon_group"
    >
    <ImageView android:id="@+id/icon"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="12dp"
        android:layout_marginBottom="12dp"
        android:layout_marginStart="12dp"
        android:layout_marginEnd="12dp"
        android:scaleType="centerInside"
        />
    <ImageView android:id="@+id/right_icon"
        android:layout_width="16dp"
        android:layout_height="16dp"
        android:padding="3dp"
        android:layout_gravity="end|bottom"
        android:scaleType="centerInside"
        android:visibility="gone"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

您可以在.../res/values/dimens.xmlnotification_large_icon_width中找到和:notification_large_icon_height

<!-- The width of the big icons in notifications. -->
<dimen name="notification_large_icon_width">64dp</dimen>
<!-- The width of the big icons in notifications. -->
<dimen name="notification_large_icon_height">64dp</dimen>
Run Code Online (Sandbox Code Playgroud)

所以最终的答案 - 128dp 用于具有 3 个或更少操作按钮的扩展布局,如果超过 3 个则为 64dp。