I have a test app where I have got a ListView with an item which contains two images on it.
As you can see in the API 17 device does not display the play button (SVG image) while the API 10 device does that. How can I fix that?
My layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/background"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:scaleType="centerCrop" />
<ImageView
android:id="@+id/forceground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
Here is my basic code where I set the images:
View preview = inflater.inflate(R.layout.list_video_preview, parent, false);
ImageView background = (ImageView)preview.findViewById(R.id.background);
ImageView forceground = (ImageView)preview.findViewById(R.id.forceground);
PictureDrawable play = SVGParser.getSVGFromResource(parent.getResources(), R.raw.play_blue).createPictureDrawable();
forceground.setImageDrawable(play);
The SVG paser is from svg-android.
The problem is the hardware acceleration. The solution is to use bitmaps instad of drawables. For fixing that I added this function to the SVG.java
which returns a BitmapDrawable
:
public BitmapDrawable createBitmapDrawable(Context context) {
Bitmap bitmap = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
PictureDrawable drawable = new PictureDrawable(picture);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return new BitmapDrawable(context.getResources(), bitmap);
}