【问题标题】:Populating image switcher dynamically android动态填充图像切换器android
【发布时间】:2013-11-09 05:56:30
【问题描述】:

当我在 drawable 文件夹和子文件夹中有图像时,如何动态填充图像切换器 .. 比如 drawable-ldpi/S_001/a001_001.jpg。

我尝试填充一张图片,但应用程序崩溃了。 代码如下:

ImageSwitcher imageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher);
imageSwitcher.setImageDrawable(getResources().getDrawable(getResources().getIdentifier("S_001/a001_001.jpg", "drawable", getPackageName())));

我需要一些帮助。

【问题讨论】:

  • 在drawable文件夹下新建文件夹不好。
  • 所以你说我复制了可绘制文件夹中的所有图像文件。那么我怎样才能在一个数组中一次获取所有的 id 呢?
  • 当我运行应用程序时,出现此错误“不幸的是,application1 已停止。”

标签: android android-drawable imageswitcher


【解决方案1】:

drawables 文件夹用于存放应用使用的 img 资源,例如图标、9-patches、背景和其他 ui 元素。 You can't put subdirectories there.

如果你打算在 ImageSwitcher 或类似的东西中使用一些照片,你应该使用assets 文件夹。 Read this to find out more.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-01
    相关资源
    最近更新 更多