2013-08-21 24 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); 
    } 
} 
相關問題