MediaStyle大图标的尺寸是多少?

11
我正在使用新的Notification.MediaStyle类为FTP流媒体播放器应用程序实现Lollipop风格的通知。我将专辑封面设置为“大图标”。鉴于专辑封面直接来自当前正在播放的文件,因此该专辑封面的大小取决于来源(可能高达5000x5000)。
从之前的代码中,我对位图进行解码,其最大大小由以下常量定义: android.R.dimen.notification_large_icon_widthandroid.R.dimen.notification_large_icon_height 这种方法非常有效,因为解码时间更快,内存使用率也很理想。
然而,在我的MediaStyle样式上应用此代码时,扩展视图使用的图标比维度参数定义的图标要大得多,导致在展开时专辑封面变得模糊。
有没有一些常量可以定义MediaStyle大图标的扩展视图的最大大小?或者有没有解决此问题的方法?目前,完全以全分辨率解码艺术品是不可接受的,因为它可能会导致OOM使应用程序崩溃。

我也遇到了同样的问题!! 在Lollipop中,解码后的位图比之前的版本“大”得多,但使用的是相同的位图和相同的源代码。你有找到任何答案或解决方法吗? - Christian
@Christian 没有得到答案或解决方法...由于 MediaStyle 的最终图形将显示为锁屏的背景,因此我选择解码到设备的最大尺寸。虽然这可能不是理想的... - initramfs
1个回答

4
从棒棒糖源代码中,我可以看到图片大小为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>

这是用于具有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>

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>

您可以在.../res/values/dimens.xml中找到notification_large_icon_widthnotification_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>

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接