Android的绘制资源ID的冲突? [英] Android drawable resource id conflict?

查看:667
本文介绍了Android的绘制资源ID的冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置的ZXing 1.7 / Android项目作为引用的库 我的主要Android应用程序项目。作为概念的快速测试/证明,我 已经使用了CaptureActivity,以同样的方式如下所述: HTTP://damianflannery.word$p$pss.com / 2011/06/13 /集成-zxing-barcod ...

I've set up the /android project of ZXing 1.7 as a library referenced by my main android app project. As a quick test / proof of concept, I have used the CaptureActivity, in the same manner as described here: http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcod...

大多数情况下,工作的事情好了,我可以启动CaptureActivity和接收 在我的活动扫描数据启动它。不过,我得到一些 真正奇怪的行为,我认为这可能与资源ID 我的项目和/ Android的ZXing项目之间的冲突。本 需要一定的解释,请多多包涵......

Mostly, things work well, I can launch the CaptureActivity and receive the scanned data in my activity that launched it. However, I get some really strange behaviour, which I think may be related to resource IDs conflicting between my project and the /android ZXing project. This will take some explaining so please bear with me...

我启动CaptureActivity与此code:

I launch the CaptureActivity with this code:

Button scanBtn = (Button)findViewById(R.id.mainmenu_btn_scan); 
scanBtn.setOnClickListener( 
    new View.OnClickListener() 
{ 
    public void onClick(View v) 
    { 
        Intent i = new Intent("com.google.zxing.client.android.SCAN"); 
        i.putExtra("SCAN_MODE", "QR_CODE_MODE"); 
        startActivityForResult(i, SCAN_CODE); 
    } 
}); 

mainmenu_btn_scan 在menu.xml文件定义的:

mainmenu_btn_scan is defined in menu.xml:

<LinearLayout android:id="@+id/mainmenu_view" style="@style/MainMenu" xmlns:android="http://schemas.android.com/apk/res/android">
    ...
    <Button android:id="@+id/mainmenu_btn_scan" 
                    android:drawableTop="@drawable/btn_scan_drawable" 
                    style="@style/MainMenuButton" 
                    android:text="Scan"/>
    ... 
</LinearLayout> 

btn_scan_drawable.xml是在/可绘,并且是一可拉伸选择器:

btn_scan_drawable.xml is in /drawable, and is a drawable selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:drawable="@drawable/scan_btn_pressed" android:state_focused="true" android:state_pressed="true" /> 
    ...
</selector>

该STANGE问题是这样的:当我拿着手机在 lanscape 的 定位和启动CaptureActivity,我看到了scan_btn_ pressed 图像拉伸在显示器上,而它的另一个副本也 整个捉襟见肘的地方取景器矩形内酒吧code 文本......当我启动活动,而持有这种情况只发生 在手机中的风景的方向。

The stange problem is this: when I hold the phone in a lanscape orientation and launch the CaptureActivity, I see the scan_btn_pressed image stretched across the display, and another copy of it also stretched across the "Place a barcode inside the viewfinder rectangle text...". This only occurs when I launch the activity while holding the phone in landscape orientation.

我发现,如果我取代

android:drawableTop="@drawable/btn_scan_drawable" 

android:drawableTop="@drawable/scan_btn_pressed"

的问题消失了,一切完美的作品,但我想要得到它与选择的工作(和理解,为什么出现问题)。如何从一个绘制我 活动的UI神秘地出现在另一活动?我是新来的Andr​​oid的发展,但我一直在谷歌上搜索,并在这个问题上一整天的工作,我似乎无法找出为什么这将是从一些模糊的引用发生除了资源在Android文档ID冲突。

The problem goes away and everything works perfectly, but I want to get it working with the selector (and understand why the problem occurs). How can a drawable from my activity's UI mysteriously show up in another activity? I'm new to Android development, but I've been googling and working at this issue all day and I can't seem to find out why this would be happening apart from some vague references to resource ID conflicts in the android docs.

注:我使用的CaptureActivity因为只有概念的快速原型/证据。我会实现我自己活动充分利用ZXIng库的最终应用程序。

Note: I am using CaptureActivity as a rapid prototype / proof of concept only. I will implement my own activity leveraging the ZXIng library for the final app.

推荐答案

好吧,似乎使用库项目时,喜欢Android系统平台拥有几道皱纹。我注意到R类我的项目和R类的ZXIng库项目是矛盾的所有的地方如:

Ok, it seems like the Android platform has a few wrinkles when using library projects. I noticed that the R class of my project and the R class of the ZXIng library project were conflicting all over the place e.g.

public static final class id {
    ...
    public static final int mainmenu_btn_scan=0x7f070028;
    ...

和在库项目的R舱:

public static final class id {
    ...
    public static final int share_app_button=0x7f070028;
    ...

这说明了如何从我的活动UI元素是被拾起,在库项目的活动。 Android将在主项目资源IDS为主。

This explains how a UI element from my activity was being picked up by an activity in the library project. Android will give priority to resources ids in the main project.

本优秀的文章给出了解决方案: HTTP:/ /blog.blackmoonit.com/2010/12/android-sharing-resources-in-eclipse.html

This excellent article gave the solution: http://blog.blackmoonit.com/2010/12/android-sharing-resources-in-eclipse.html

在CaptureActivity(活动我打电话在图书馆),我换成

In CaptureActivity (the activity I was calling in the library), I replaced

viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);

通过这种

viewfinderView = (ViewfinderView) findViewById(
    getResources().getIdentifier("viewfinder_view", "id", getPackageName()) );

这解决了该问题,但我需要办理和更换getIndentifier()所有直接标识引用,以确保没有任何其他冲突。不是一个理想的解决方案。这感觉就像应该有一些相当简单的扩展,AAPT工具,以确保是R类之间的ID不冲突。

This fixed the issue, although I'll need to go through and replace all direct id references with getIndentifier() to ensure there aren't any other conflicts. Not an ideal solution. It feels like there ought to be some fairly straightforward extension to the aapt tool to ensure that the ids between R classes don't conflict.

在这里看到更多的信息:<一href="http://devmaze.word$p$pss.com/2011/05/22/android-application-android-libraries-and-jar-libraries/" rel="nofollow">http://devmaze.word$p$pss.com/2011/05/22/android-application-android-libraries-and-jar-libraries/

See here for more info: http://devmaze.wordpress.com/2011/05/22/android-application-android-libraries-and-jar-libraries/

这篇关于Android的绘制资源ID的冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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