我的 Android 应用程序中有很多图像,我试图将它们组织在 assets 目录下的文件夹中,而不是将它们全部放在 drawable 目录中。
我的问题是如何通过 XML 访问 Assets 目录。例如:
<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"/>
不起作用。有什么我可以放在 src 字符串中来完成这项工作的吗?或者只能使用代码中的 AssetManager 访问 Assets 。
最佳答案
你为什么不把你的图像放在“drawable”-Recourse 文件夹中?那是他们属于的地方。然后可以使用类似这样的 XML 访问这些图片:
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/your_file"
/>
位于“assets”文件夹中的文件使用 AssetManager 访问,它返回所需文件的 InputStream。我不知道有什么方法可以通过 XML 访问它们。
关于android - 从 XML 访问 android Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5733515/