如何消耗可重复使用的GUI元素/小部件与Android的资源 [英] How to consume reusable gui element/widget with resources in android

查看:182
本文介绍了如何消耗可重复使用的GUI元素/小部件与Android的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 dateslider 在我的Andr​​oid项目有组合的日期时间选择器即时通讯我的GUI。

小工具的作者建议直接包括Java和资源来源为我的应用程序。

第一次尝试复制Java和资源为主要的应用程序:

结果:窗口小部件的Java类的不能编译,因为resourceids R.xxxx解决不了

原因:窗口小部件类在包中实现com.google code.android.widgets.DateSlider和我的应用程序 有不同的命名空间my.namespace.myApp,使resourceids来自my.namespace.myApp.R.xxx。

解决此我将不得不触动每一个部件java源导入my.namespace.myApp。

有没有办法有2个资源集不同的命名空间,以便有my.namespace.myApp.R.xxx和c $ c.android.widgets.DateSlider.R com.google $主应用程序?

2日试试把小部件的java +资源投入到单独的JAR /库:

结果:每一件事情编译。但AppStart的后,我得到一个 runtimererror:运行时无法解析从罐子里/ lib中的小部件资源ID

注:我可以打电话从罐子里的方法,只要这些不需要的资源

所以我的问题:什么是消耗在Android中的资源可重复使用的GUI元素的最佳方式

我使用的Andr​​oid 2.2。

注:<一href="http://stackoverflow.com/questions/4300276/android-how-do-i-create-reusable-components">Android:如何创建可重用的组件?没有帮助,因为它会告诉你如何创建库项目。

更新2012年3月16日

由于当前版本的16 / 17- $ P $ Eclipse的ADT-工具不支持资源罐(截至尝试2)中的对什么是消耗他们,直到有支持这一点的最好/最简单的方法?

更新2012年4月4日

与新的R17-工具,我成功地消耗libraryproject与 - 资源创建的罐子。 Android的皮棉帮我找出在lib改一下,使其可用。

  • 日食工作区

    • DateSliberLib
      • 的src
      • RES
      • ...
    • MyAppUsingLib
      • 的src
      • RES
      • ...

    用这个布局MyAppUsingLib运行良好


不过我还是不能独立使用DateSliberlib.jar

  • 在日食工作区
    • MyAppUsingLib
      • 的src
      • RES
      • LIB
        • DateSliberLib.jar
      • ...

此设置可以comiled但应用程序崩溃,因为它无法找到的lib的资源。

[更新2014年11月17号]

3个月前,我从月食/蚂蚁构建切换到Android的工作室,引进是JAR档案与Android资源* .aar文件/摇篮构建。

Android的工作室/摇篮构建能应对资源库。

解决方案
  

有没有办法有2个资源集不同的命名空间,以便有my.namespace.myApp.R.xxx和c $ c.android.widgets.DateSlider.R com.google $主应用程序?

没有,不好意思。

  

注:Android的:如何创建可重用的组件?没有帮助,因为它会告诉你如何创建库项目。

然而,的的正确答案。从回购下载完整的项目,将其导入到Eclipse中,并标记为一个库项目(属性> Android的)。然后,将其添加为库项目,以您的应用程序的项目。

最后,(现在看起来像这将是R18版本的工具或更高版本),该工具应该支持包装可重用的组件在一个JAR,与资源,以这样的方式,你可以将它们添加到主机项目和资源将被自动混入。眼下,这不是一个选项。

I try to use the dateslider in my android project to have a combined date-time picker im my gui.

The authors of the widget suggest to include the java- and resource-sources directly into my app.

1st try copy java and resources into main app:

Result: The widget java classes cannot compile because the resourceids R.xxxx cannot be resolved.

Reason: The widget classes are implemented in package "com.googlecode.android.widgets.DateSlider" and my app has a different namespace "my.namespace.myApp" so that the resourceids come from my.namespace.myApp.R.xxx.

To fix this i would have to touch every widget java source to import my.namespace.myApp.

Is there a way to have 2 resource-sets with different namespaces so that there are my.namespace.myApp.R.xxx and com.googlecode.android.widgets.DateSlider.R in the main app?

2nd try put widget java+resources into seperate jar/library:

result: every thing compiled. but after appstart i get a runtimererror: the runtime cannot resolve the widget resource IDs from the jar/lib.

Note: i can call methods from the jar as long as these do not need resources.

So my question: what is the best way to consume a reusable gui element with resources in android?

I am using android 2.2.

Note: Android: How do I create reusable components? does not help because it tells you how to create library-projects.

update 16.3.2012

Since the current version 16 /17-pre of of the eclipse adt-tools do not support resources in jars (as of try 2) what is the best/easiest way to consume them until there is support for this?

update 4.4.2012

with the new R17-tools i succeeded to consume libraryproject-with-resources that creates the jar. Android-Lint helped me to find out what to change in the lib to make it usable.

  • eclipse-workspace

    • DateSliberLib
      • src
      • res
      • ...
    • MyAppUsingLib
      • src
      • res
      • ...

    with this layout MyAppUsingLib is running fine


However I am still not able to use the DateSliberlib.jar alone

  • eclipse-workspace
    • MyAppUsingLib
      • src
      • res
      • lib
        • DateSliberLib.jar
      • ...

This setting can be comiled but the app crashes because it cannot find the resources of the lib.

[update 2014-11-17]

6 months ago i switched from eclipse/ant-build to android-studio/gradle build which introduced *.aar files that are jar-files with android resources.

android-studio/gradle build can cope with resources in libs.

解决方案

Is there a way to have 2 resource-sets with different namespaces so that there are my.namespace.myApp.R.xxx and com.googlecode.android.widgets.DateSlider.R in the main app?

No, sorry.

Note: Android: How do I create reusable components? does not help because it tells you how to create library-projects.

However, that is the right answer. Download the full project from their repo, import it into Eclipse, and mark it as a library project (Properties > Android). Then, add it as a library project to your app's project.

Eventually (which now appears like it will be the R18 version of tools or later), the tools should support packaging reusable components in a JAR, with resources, in such a manner that you can add them to a host project and the resources will be blended in automatically. Right now, that's not an option.

这篇关于如何消耗可重复使用的GUI元素/小部件与Android的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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