繁体   English   中英

从xml文件创建drawable

[英]create drawable from xml file

我正在使用map并尝试从我的布局文件中创建标记为Drawable对象。 我需要更改标记视图取决于点的类型,因此我将第一个图像声明为静态,将第二个图像声明为动态(动态更改),但它不起作用。

我的布局文件

 <?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>

我的代码:

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();
}

Drawable.createFromXml不用于将LayoutsView加载到drawable !! 看到它的用法示例:

http://spearhend.blogspot.com/2012/04/load-android-drawable-from-xml.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM