【问题标题】:Assets folder in TitaniumTitanium 中的资产文件夹
【发布时间】:2011-06-30 14:44:56
【问题描述】:

我编写了一个模块,该模块创建了一个覆盖有 imageView 的 cameraview 来拍摄照片,我的问题是,由于我无法将图像传递到“res”文件夹中,我需要将它放在“assets”中,纯java 一切正常,但是一旦我导出模块,我就不知道在钛项目中放置“资产”文件的位置。 当我使用 IOException 调用该方法时它会崩溃。 谢谢

    FrameLayout fl = new FrameLayout(this);
    SurfaceView preview = new SurfaceView(this);
    ImageView footerCam = new ImageView(this);
    LinearLayout ll = new LinearLayout(this);

    LinearLayout.LayoutParams shareParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    footerCam.setLayoutParams(shareParams);
    ll.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);

    ll.addView(footerCam);
    fl.addView(preview);
    fl.addView(ll);

    setContentView(fl);
    camera = Camera.open();

    try 
    {
     AssetManager am = getAssets();
     BufferedInputStream buf = new BufferedInputStream(am.open("footer1.png"));
     Bitmap bitmap = BitmapFactory.decodeStream(buf);
     footerCam.setImageBitmap(bitmap);
     buf.close();
   }   
   catch (IOException e) 
   {
       Log.e("IMG","@@@@@@@@@@@@@@@@@@@@@@@ ERROR LOADING IMAGE");
       e.printStackTrace();
   }

这是我声明按钮并为其分配资产文件夹中的图像的一段代码,但仅适用于 android,当我部署模块并将其包含在钛中时,它属于 IOException,我需要在哪里放置文件“footer1.png”还是“assets”文件夹?

【问题讨论】:

    标签: android appcelerator-mobile titanium-modules


    【解决方案1】:

    我用这种方法来管理它

    int resID = getResources().getIdentifier("IMG.png", "drawable", "it.temp");
    // or
    int resID = getResources().getIdentifier("it.temp:drawable/icon",null,null);
    
    button.setBackgroundResource(resID);// or whatever you need
    

    但您必须将图像与源代码放在同一个包中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-29
      • 2012-03-10
      • 2013-10-14
      • 2011-11-24
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多