从XML访问android资产

mat*_*typ 5 android assets image

我的Android应用程序中有很多图像,并且试图将它们组织在assets目录下的文件夹中,而不是将它们放在drawable目录中.

我的问题是如何通过XML访问资产目录.例如:

        <ImageView android:id="@+id/image_team_logo" 
            android:src="/assets/teamlogos/ARI" 
            android:layout_height="25dp" 
            android:layout_marginLeft="5dp" 
            android:layout_marginTop="10dp" 
            android:layout_width="296dp" android:scaleType="matrix"/>
Run Code Online (Sandbox Code Playgroud)

不行.我可以在src字符串中放置一些东西来使其工作吗?或者只能使用代码中的AssetManager访问资产.

Luk*_*uth 3

你为什么不把你的图像放在"drawable"-Recourse文件夹中?这就是他们所属的地方.然后可以使用以下内容以XML格式访问这些图片:

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/your_file"
 />
Run Code Online (Sandbox Code Playgroud)

使用AssetManager访问位于"assets"-Folder中的文件,AssetManager在所需的File上返回InputStream.我不知道通过XML访问它们的方法.

  • drawable文件夹不允许子文件夹,我试图以某种方式管理我的资产,所以它不是一个糟糕的节目......但听起来像Android希望你只有100个图像都在同一目录... (4认同)