在android中使用矢量图像的真实设备上出现问题。SVG android
我使用在android中使用矢量图像的真实设备上出现问题。SVG android,android,svg,imageview,Android,Svg,Imageview,我使用svg-android.jarfromhttps://github.com/pents90/svg-android工作正常,但仅限于eclipse中的模拟器设备。阿格雷尔。在真正的设备上,它只是在屏幕上清空imageView。 这是我的密码: SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.test); Drawable drawable = svg.createPictureDrawable(); imgView.
svg-android.jar
fromhttps://github.com/pents90/svg-android
工作正常,但仅限于eclipse中的模拟器设备。阿格雷尔。在真正的设备上,它只是在屏幕上清空imageView
。
这是我的密码:
SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.test);
Drawable drawable = svg.createPictureDrawable();
imgView.setImageDrawable(drawable);
有什么建议吗?在默认情况下已打开硬件渲染的较新设备上,您需要显式打开软件渲染
imgView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
我怀疑这可能是您的问题。使用AppCompatImageView代替xml格式的ImageView,如下面的代码所示
<android.support.v7.widget.AppCompatImageView
android:tint="#d74313"
app:srcCompat="@drawable/circle_icon"
android:layout_width="30sp"
android:layout_height="30sp" />
如果上述方法无效,请在应用程序类中也尝试此方法
public class App extends Application {
@Override public void onCreate() {
super.onCreate();
// Make sure we use vector drawables
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
}
请注意,您也可以在XML中这样做
android:layerType=“software”
只需使用AppCompatImageView+srcCompat就可以了,谢谢
public class App extends Application {
@Override public void onCreate() {
super.onCreate();
// Make sure we use vector drawables
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
}