android - RemoteViews 构造函数中的包名称是什么?

标签 android android-appwidget android-remoteview

来自 the documentation , RemoteViews 的构造函数是

public RemoteViews (String packageName, int layoutId)

文档说 packageName 是“包含布局资源的包的名称”。

  • 为什么需要这个?
  • layoutId 不会告诉您关于布局资源位置的所有信息吗?
  • 你会把什么作为包名?
  • 它不会总是 res->layout 吗?

最佳答案

既然 Sirlate 已经回答了“为什么需要这个?”,我将尝试回答其余的问题。

Wouldn't the layoutId tell you everything that you need to know about the location of the layout resource?

不是,layoutId,和其他资源的ID一样,只是一个数字。当您通过 R.layout.some_layout 引用它时,它实际上引用了 ID 本身,作为一个数字。

Wouldn't it always be res->layout?

其实不是!您可以将任何资源放在任何文件夹中(只要在 /res 内),即使它是布局资源。 /res/layout/ 只是一个方便的文件夹,因为 Android 已经首先定义了它。毕竟,Android 只会将资源引用为 ID 号。

What would you put as the package name?

如 Sirlate 所述,您要使用布局的应用的包名称。

Why is this needed?

除了 Sirlate 的回答外,如果您只有资源 ID,操作系统将无法确定布局来自哪个包/应用程序。

关于android - RemoteViews 构造函数中的包名称是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25322148/

相关文章:

android - 为什么改造要重新排序我的 QueryMap 参数?

安卓。 Firebase crashlytics 解释

android - 将整数数组从 AppWidget 传递到预先存在的 RemoteViewsService 以由 RemoteViewsFactory 呈现

Android ICS 1x1 小部件文本标签

Android ListView 小部件有时对点击无响应

java - Udacity Sunshine 应用程序第 1 课

android - 如何将线性布局 xml 文件合并到撰写文件中?

java - 手机锁定一段时间后,appWidget 停止更新/工作

Android 主屏幕小部件动态调整文本大小

android - NotificationListenerService中如何获取Notification内容详情