2013-08-21 14 views
26

我使用https://github.com/pents90/svg-androidsvg-android.jar工作正常,但只在eclipse中的仿真器设备上。 Agrrrr。在真实设备上,它仅在屏幕上清空imageView。 这里是我的代码:在Android上使用矢量图像的Real Device上出现问题。 SVG-android

SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.test); 
Drawable drawable = svg.createPictureDrawable(); 
imgView.setImageDrawable(drawable); 

有什么建议吗?

回答

44

在默认打开硬件渲染的新设备上,您需要明确打开软件渲染。

imgView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 

我怀疑这可能是您的问题。

+0

非常感谢!!!!!!!它的工作原理) –

+13

请注意,您可以在XML中执行此操作'android:layerType =“software”' – William

0
Use AppCompatImageView instead Imageview in xml like the below code 

    <android.support.v7.widget.AppCompatImageView 
    android:tint="#d74313" 
    app:srcCompat="@drawable/circle_icon" 
    android:layout_width="30sp" 
    android:layout_height="30sp" /> 


and in your build.gradle 

    android { 
    defaultConfig { 
    vectorDrawables { 
     useSupportLibrary = true 
    } 
    } 
} 

If the above doesn't work, try this also in your application class 

    public class App extends Application { 

    @Override public void onCreate() { 
    super.onCreate(); 

    // Make sure we use vector drawables 
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); 
    } 
} 
相关问题