Android的自定义状态栏通知bug?

发布于 2024-10-18 00:20:20 字数 1749 浏览 5 评论 0原文

我试图通过远程视图在状态栏上显示自定义通知内容。我对宽度和高度都使用 fill_parent ,但右侧总是有一个小间隙。我在这里做错了什么?

请参阅此处的屏幕截图: http://img684.imageshack.us/img684/2347/ devicenq.png

布局代码(我也使用了LinearLayout):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="@color/solid_yellow"
              >
    <ImageView android:id="@+id/image"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:layout_marginRight="10dp"
              android:src="@drawable/stat_sample"
              />
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:textColor="#000"
              android:text="Hello, this message is in a custom expanded view"
              />
</RelativeLayout>

这是代码片段:

Intent notificationIntent = new Intent(this, MessengerService.class);
PendingIntent contentIntent = PendingIntent.getActivity(
    this, 0, notificationIntent, 0);

Notification notification = new Notification(R.drawable.stat_sample,
    "Hello", System.currentTimeMillis());

RemoteViews contentView = new RemoteViews(getPackageName(),
    R.layout.custom_notification_layout);

notification.contentView   = contentView;
notification.contentIntent = contentIntent;

mNM.notify(R.string.remote_service_started, notification);

我整天都在用这个敲脑袋...... 谢谢。

I am trying to show a custom notification content on the status bar via Remote View. I am using fill_parent for both width and height, but there is always a small gap on the right side. What am I doing wrong here?

Please see the screen shot here: http://img684.imageshack.us/img684/2347/devicenq.png

Layout code (I also used LinearLayout):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="@color/solid_yellow"
              >
    <ImageView android:id="@+id/image"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:layout_marginRight="10dp"
              android:src="@drawable/stat_sample"
              />
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:textColor="#000"
              android:text="Hello, this message is in a custom expanded view"
              />
</RelativeLayout>

And here is the code snippet:

Intent notificationIntent = new Intent(this, MessengerService.class);
PendingIntent contentIntent = PendingIntent.getActivity(
    this, 0, notificationIntent, 0);

Notification notification = new Notification(R.drawable.stat_sample,
    "Hello", System.currentTimeMillis());

RemoteViews contentView = new RemoteViews(getPackageName(),
    R.layout.custom_notification_layout);

notification.contentView   = contentView;
notification.contentIntent = contentIntent;

mNM.notify(R.string.remote_service_started, notification);

I have been banging my head all day with this...
Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九歌凝 2024-10-25 00:20:20

你有一个

 android:layout_marginRight="10dp"

,此时右侧的空格出现

You have a

 android:layout_marginRight="10dp"

and that's when this space on the right appears

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文