I’m having trouble declaring my bitmap/drawable in appropriate xml
According to “convoluted” android docs, you can declare drawables a dozen ways such
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/myimage" />
OR
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/icon"
android:tileMode="repeat" />
OR , etc…
Belows are 2 examples of the dozen drawables.xml that I have tried without success.
Example 1:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<item xmlns:android="http://schemas.android.com/apk/res/android" android:id="@id/enemyAirplane1" android:drawable="@drawable/enemyAirplane1" >
<bitmap android:src="@drawable/enemyAirplane1" />
</item>
<item xmlns:android="http://schemas.android.com/apk/res/android" android:id="@id/playerShape1" android:drawable="@drawable/playerShape1">
<bitmap android:src="@drawable/playerShape1" />
</item>
</resources>
Example 2:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<bitmap android:src="@drawable/enemyAirplane1" />
<bitmap android:src="@drawable/playerShape1" />
</resources>
Finally my exact questions are:
1) What should be the name of xml that declares drawable/bitmap resources (drawables.xml) or ?
2) Were should the xml file reside/in which resource folder (res/values) OR ?
3) Can someone provide a working example of bitmap declared in xml , without any xml or IDE errors?
If you have a bitmap file (.png, .jpg, or .gif), you may place it in res/drawable/ (or any annotated version of res/drawable/ such as res/drawable-hdpi) and refer to it in your layout files as in your first code snippet. That snippet will look in res/drawable for one of four possibilities : myimage.png, myimage.jpg, myimage.gif, or myimage.xml. Bitmaps declared in xml files also must refer to a resource of .png, .jpg, or .gif. The declaration in an xml file is for creating an alias and/or specifying additional properties such as dithering.
To answer your specific questions:
resources. You just drop your files in the res/drawable/ folder.
resources.
resources. Snake is a simple example.