【问题标题】:How to add vertical line to RemoteView for custom Android Notifications?如何为自定义 Android 通知添加垂直线到 RemoteView?
【发布时间】:2012-05-23 08:10:03
【问题描述】:

我正在努力为自定义 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 发布的错误通知:无法扩展 RemoteViews:StatusBarNotification(package=XXX)

有人有什么想法吗?

【问题讨论】:

    标签: android android-layout view android-notifications remoteview


    【解决方案1】:

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

    RemoteViews 对象(因此,App Widget)可以支持以下布局类:

    FrameLayout
    LinearLayout
    RelativeLayout
    

    还有以下小部件类:

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

    不支持这些类的后代。

    参考:http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout

    【讨论】:

    • 你这个男人 K-ballo。使用 ImageView 效果很好。这是我的代码:&lt;ImageView android:id="@+id/image_logo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:contentDescription="@string/app_name" /&gt;
    • 感谢您的解释。
    【解决方案2】:
        <LinearLayout
            android:layout_width="1dp"
            android:layout_height="25dp"
            android:layout_gravity="center_vertical"
            android:alpha="0.3"
            android:background="#FFFFFF" />
    

    我们必须像这样添加。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-21
      相关资源
      最近更新 更多