mattyp
mattyp

Reputation: 155

Access android assets from XML

I have lots of images in my Android app and was trying to get them organized in folders under the assets directory as opposed to having them all site in the drawable directory.

My question is how can I access the assets directory through XML. For instance:

        <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"/>

Does not work. Is there something I can put in the src string to make this work? Or are assets only accessible using the AssetManager in code.

Upvotes: 5

Views: 8969

Answers (1)

Lukas Knuth
Lukas Knuth

Reputation: 25755

Why don't you put your Images in the "drawable"-Recourse folder? That's where they belong. Those pictures can then be accessed in XML using something like this:

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/your_file"
 />

Files located in the "assets"-Folder are accessed with the AssetManager, which returns an InputStream on the desired File. I don't know any way of accessing them through XML.

Upvotes: 3

Related Questions