Android:将VectorDrawable添加到ImageView

时间:2017-04-13 13:41:31

标签: java android imageview android-vectordrawable

所以,我想用可点击的国家制作一个可滚动的世界地图。所以当我发现有VectorDrawables这样的东西时,我决定尝试一下。

我接下来要做的是从VectorDrawable xml制作一个SVG文件并尝试将其放入我的ImageView。在搜索一些信息时,我发现有101种方法可以做到这一点,而且没有一种方法可以帮助我...... 有趣的是,当我在"android:src="@raw/worldmap"的{​​{1}}中添加ImageView时,地图会显示在预览中,但每当我尝试运行该应用时,它都会崩溃。< / p>

activity.xml

1 个答案:

答案 0 :(得分:1)

首先,将您的VectorDrawable移至Drawable文件夹(不是原始文件夹)。然后,在Gradle文件中添加以下行:

defaultConfig{
vectorDrawables.useSupportLibrary = true
}

最后,在您的imageView中,更改为此;

 <ImageView
        android:id="@+id/img"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#fff"
        android:scaleType="center"
       app:srcCompat="@drawable/worldmap">
    </ImageView>
相关问题