【问题标题】:Size of MediaStyle LargeIconMediaStyle 大图标的大小
【发布时间】:2015-03-15 02:31:54
【问题描述】:

我正在使用新的 Notification.MediaStyle 类为 FTP 流音乐播放器应用程序实现棒棒糖样式的通知。我将专辑封面设置为我的“大图标”。

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

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

android.R.dimen.notification_large_icon_height

效果很好,因为解码时间更快,内存使用也很理想。

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

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

【问题讨论】:

  • 我遇到了同样的问题!!在棒棒糖中,解码的位图看起来比棒棒糖前“大”得多,但具有相同的位图和相同的源代码。您得到任何答案或解决方法了吗?
  • @Christian 没有得到答案或解决方法...因为MediaStyle 的最终图形显示为锁定屏幕的背景,我选择解码为设备的最大尺寸。虽然这可能并不理想......

标签: android android-notifications bitmapfactory android-bitmap


【解决方案1】:

从 Lollipop 源代码中我可以看到图像大小为 128dp,参见 notification_template_material_big_media.xml on GitHub:

<!-- 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 个或更少操作按钮的扩展布局。期待Notification.MediaStyle.getBigLayoutResource(int) on GrepCode,如果有更多按钮,似乎使用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>

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

【讨论】:

    猜你喜欢
    • 2018-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-31
    • 2018-09-04
    • 1970-01-01
    • 2021-12-24
    相关资源
    最近更新 更多