27

我在它的工作中使用svg-android.jarfromhttps://github.com/pents90/svg-android很好,但只在 eclipse 中的模拟器设备上使用。啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊 在真实设备上,它只是imageView在屏幕上为空。这是我的代码:

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

有什么建议吗?

4

2 回答 2

45

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

imgView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

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

于 2013-08-21T13:24:10.460 回答
1

在 xml 中使用 AppCompatImageView 代替 ImageView,如下面的代码

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

在你的 build.gradle

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

如果上述方法不起作用,请在您的应用程序类中尝试此操作

public class App extends Application {

  @Override public void onCreate() {
    super.onCreate();
    // Make sure we use vector drawables
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
  }
}
于 2017-08-29T06:09:44.260 回答