多个部件尺寸 [英] Multiple widget sizes

查看:139
本文介绍了多个部件尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很抱歉,但在英语这可能是十分难以解释的问题。 :)所以我会尽量做到简单,只要我可以:)

I apologize, but in english it might be quite difficult to explain the problem. :) so I will try to do it as simple as I can :)

我正在寻找在互联网,但没有什么帮助。我想打第二个小部件,只是更大。使用即时通讯服务来更新我的部件,所以我需要(通过remoteviews等部件中的更新数据),以创建2个服务,或者我可以更容易?

I was searching in internet but nothing helps. I want to make second widget, just bigger. Im using service to update my widget so I need to create 2 services (update data in widget by remoteviews etc.) or can I make it easier?

当我中添加小部件,它显示了TE小的,但它需要更多的空间(144dp点¯x72dp)并没有更新。也许我应该复制整个应用程序的类和修改它,但我认为这是愚蠢的解决方案。

When I add medium widget, it shows up te small one but it takes more space (144dp x 72dp) and there is no update. Maybe I should copy whole app classes and modify it, but I think this is stupid solution.

我尝试这个解决方案

如何在一个应用程序中添加多个小部件?

如何把多个部件尺寸在一个APK <? / A>

How to put multiple widget sizes in one apk?

任何提示? :)

推荐答案

我和我的小部件同样需要。 $ P $你已经张贴帮我找到解决办法pcisely这两个环节,这终于来到与更多的研究了一下。

I had the same need with my widget. Precisely those two links you have posted helped me find the solution, which came at last with a bit more of research.

在为了有一个第二尺寸为您的小部件:

In order to have a second size for your widget:


  1. 定义另一个接收器在您的清单中,有diferent名。这一点很重要:如果你不使用不同的名字,只有一个会在可用小部件的列表中显示。例如:的android:MyWidget_SmallNAME = 的android:NAME =。MyWidget_Medium。也相应修改标签

额外的接收器需要在res / xml的一个新的appwidget提供商。在安卓:元数据标签类型另一个XML文件的名称资源。你必须再安卓资源=@ XML / MyWidgetProvider_Small安卓资源=@ XML / MyWidgetProvider_Medium

The additional receiver needs a new appwidget provider in res/xml. In android:resource of the meta-data tag type the name of another XML file. You'll have then android:resource="@xml/MyWidgetProvider_Small" and android:resource="@xml/MyWidgetProvider_Medium"

在res / XML每个XML文件必须指向一个单独的布局。您将有的android:initialLayout =@布局/ MyWidget_Small的android:initialLayout =@布局/ MyWidget_Medium

Each XML file in res/xml must point to a separate layout. You will have android:initialLayout="@layout/MyWidget_Small" and android:initialLayout="@layout/MyWidget_Medium"

现在在Java的一部分。每个appwidget提供商需要扩展AppWidgetProvider,所以你需要两个额外的类及其对应的Java类。如果你原来的班是MyWidget.java,您将添加MyWidgetSmall.java和MyWidgetMedium.java。你可能最终会继承原来的Java类,也许对矫正​​每一个新的类,如果小部件都有每个尺寸明显行为。记得您在步骤1中的接收器的Andr​​oid那样来命名两类:名称

Now the Java part. Each appwidget provider need its correspondent Java class that extends AppWidgetProvider, so you will need two additional classes. If your original class was MyWidget.java, you'll add MyWidgetSmall.java and MyWidgetMedium.java. You'll probably end up subclassing your original Java class, and perhaps modifing each new class if the widget has a distinct behavior in each size. Remember to name the two classes as you did in step 1 in the receivers's android:name

您服务不需要重复。然而,你应该检查你的源$ C ​​$ C找到MyWidget.class明确提及的发生。如果你这样做,你必须引用实际子类

Your service doesn't need duplication. However you should examine your source code to find occurrences of explicit references to MyWidget.class. If you did this, you must reference the actual subclass

希望这有助于

这篇关于多个部件尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆