在运行时设置 RemoteView 中的视图位置
我正在寻找一种方法来更改视图中的位置 运行时的主屏幕小部件/远程视图。 我之前也看到过这个主题,但那里给出的答案没有不帮助我,甚至不工作。
例如:
我试图将 TextView 的 x 位置移动 5 个像素:
myRemoteView.setFloat(R.id.myTextView, "setTranslationX", 5); // does not work
myRemoteView.setFloat(R.id.myTextView, "setX", 5); // does not work
myRemoteView.setInt(R.id.myTextView, "setLeft", 5); // does not work
我在其他地方找不到可以帮助我的有用答案。
I'm looking for a way to change the position of a view in a
homescreen widget/remoteview during runtime.
I also saw this topic before but the answer given there didn't help me or even work.
For example:
I'm trying to shift the x position of the TextView by 5 pixels:
myRemoteView.setFloat(R.id.myTextView, "setTranslationX", 5); // does not work
myRemoteView.setFloat(R.id.myTextView, "setX", 5); // does not work
myRemoteView.setInt(R.id.myTextView, "setLeft", 5); // does not work
I couldn't find somewhere else a useful answer that could help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用
RemoteViews
扩展一种不同的布局,其中的小部件位于您想要的位置。我不确定它是否有效,但值得一试。You could try inflating a different layout with your
RemoteViews
, one with the widgets in your desired position. I am not sure that it will work, but it is worth a try.从 API 31 开始,setTranslationX 可以在 RemoteView 上调用,因为它已被注释为 RemotableViewMethod。使用:
或使用 RemoteViewsCompat 中的扩展方法:
Since API 31, setTranslationX can be called on RemoteViews, since it is has been annotated as RemotableViewMethod. Either with:
or by using an extension method from RemoteViewsCompat: