gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 12:53:32 25 4
gpt4 key购买 nike

来自 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com