如何为自定义Android通知在RemoteView中添加垂直线?

4

我想要在自定义的Android通知中加入一条竖线,但是我很困难。我尝试在相对布局中添加以下视图:

<View
    android:id="@+id/line_vertical"
    android:layout_width="1dip"
    android:layout_height="fill_parent"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@id/image_logo"
    android:background="#0000FF" />

但是当我触发通知时,我会收到以下异常:
android.app.RemoteServiceException:包XXX发布的通知不好:不能为StatusBarNotification(package = XXX)扩展RemoteViews。
有人有什么想法吗?
2个回答

6

您不能在RemoteView中填充任何视图。将您的View更改为空的TextViewImageView

A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:

FrameLayout
LinearLayout
RelativeLayout

And the following widget classes:

AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
ViewFlipper
ListView
GridView
StackView
AdapterViewFlipper

Descendants of these classes are not supported.

参考文献:http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout 本文介绍了如何创建 Android 应用程序小部件的布局。为了让小部件适应不同尺寸的屏幕和方向,可以采用不同的布局方案。此外,还可以使用 RemoteViews 类来动态地更新小部件的布局。详细内容请参见上述链接。

你是大牛 K-ballo。使用 ImageView 完美解决问题。这是我的代码: - Karim Varela
感谢您的解释。 - Ogulcan Orhan

2
    <LinearLayout
        android:layout_width="1dp"
        android:layout_height="25dp"
        android:layout_gravity="center_vertical"
        android:alpha="0.3"
        android:background="#FFFFFF" />

我们需要像这样添加。

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