erstellen drawable aus der xml-Datei
Ich arbeite mit der Karte und versuchen, um marker als Drawable-Objekt aus meinem layout-Datei.
Ich brauche meine marker-Ansicht zu ändern, hängt von der Art der Stelle, und daher erklärte ich mein erstes Bild als statisches und mein zweites Bild als dynamic(dynamisch Ändern),aber es funktioniert nicht.
Meine layout-Datei
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<ImageView
android:id="@+id/marker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/marker" >
</ImageView>
<ImageView
android:id="@+id/category"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/category_for_children" />
</RelativeLayout>
Mein code:
Resources res = getResources();
try {
marker = Drawable.createFromXml(res, res.getXml(R.layout.marker_on_map));
} catch (NotFoundException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Du musst angemeldet sein, um einen Kommentar abzugeben.
Drawable.createFromXml
ist nicht für das ladenLayouts
oderView
in drawable!!siehe dieses Beispiel für die Verwendung:
http://spearhend.blogspot.com/2012/04/load-android-drawable-from-xml.html