Java Android:向ImageView添加矢量绘图
所以,我想制作一张带有可点击国家的可滚动世界地图。因此,当我发现有一种类似矢量绘图的东西时,我决定尝试一下 我做的下一件事是用SVG制作一个可矢量绘制的xml文件,并尝试将其放在我的ImageView中。在搜索一些信息时,我发现有101种方法可以做到这一点,但没有一种对我有效。。。 有趣的是,当我在activity.xml的ImageView中添加android:src=@raw/worldmap时,地图会显示在预览中,但每当我尝试运行应用程序时,它就会崩溃Java Android:向ImageView添加矢量绘图,java,android,imageview,android-vectordrawable,Java,Android,Imageview,Android Vectordrawable,所以,我想制作一张带有可点击国家的可滚动世界地图。因此,当我发现有一种类似矢量绘图的东西时,我决定尝试一下 我做的下一件事是用SVG制作一个可矢量绘制的xml文件,并尝试将其放在我的ImageView中。在搜索一些信息时,我发现有101种方法可以做到这一点,但没有一种对我有效。。。 有趣的是,当我在activity.xml的ImageView中添加android:src=@raw/worldmap时,地图会显示在预览中,但每当我尝试运行应用程序时,它就会崩溃 <LinearLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="@+id/activity_show_hint"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.bert.myapplication.ShowHintActivity"
android:weightSum="1">
<ImageView
android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:scaleType="center"
android:src="@raw/worldmap">
</ImageView>
</LinearLayout>
首先,将VectorDrawable移动到不在raw中的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>
你在运行哪个操作系统?我在运行Ubuntu 16.04.2