【问题标题】:How to know the picture size in the Android Notification big picture style?Android Notification 大图样式如何知道图片大小?
【发布时间】:2017-05-23 15:07:47
【问题描述】:

【问题讨论】:

    标签: android notifications


    【解决方案1】:

    BigPictureStyle 通知图像的大小

    最小 - 512x256

    平衡 - 1024x512

    最大 - 2048x1024

    从这个答案中得到https://stackoverflow.com/a/33391039/5783417

    注意:在较小的设备 (800x480) 中,仍然存在中心裁剪 发生

    【讨论】:

    • 有 2:1 比例和 800x480 的来源吗?
    【解决方案2】:

    试试这个代码

     Notification notif = new Notification.Builder(mContext)
         .setContentTitle("New photo from " + sender.toString())
         .setContentText(subject)
         .setSmallIcon(R.drawable.new_post)
         .setLargeIcon(aBitmap)
         .setStyle(new Notification.BigPictureStyle()
             .bigPicture(aBigBitmap))
         .build();
    

    【讨论】:

    • 先谢谢!但我需要知道 ImageView 的大小
    【解决方案3】:

    要让通知出现在展开的视图中,首先使用所需的普通视图选项创建一个 NotificationCompat.Builder 对象。接下来,使用展开的布局对象作为参数调用 Builder.setStyle()。

    请记住,扩展通知在 Android 4.1 之前的平台上不可用。要了解如何处理 Android 4.1 和更早平台的通知,请阅读处理兼容性部分。

    例如,以下代码 sn-p 演示了如何更改在之前的 sn-p 中创建的通知以使用扩展布局:

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.notification_icon)
    .setContentTitle("Event tracker")
    .setContentText("Events received")
    NotificationCompat.InboxStyle inboxStyle =
        new NotificationCompat.InboxStyle();
    String[] events = new String[6];
    // Sets a title for the Inbox in expanded layout
    inboxStyle.setBigContentTitle("Event tracker details:");
    ...
    // Moves events into the expanded layout
    for (int i=0; i < events.length; i++) {
      inboxStyle.addLine(events[i]);
    }
    // Moves the expanded layout object into the notification object.
    mBuilder.setStyle(inboxStyle);
    ...
    // Issue the notification here.
    

    你也可以参考这个链接,Applying an expanded layout to a notification

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-08
      • 2011-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多