私のアプリケーションの背景としてSVGイメージ(Inkscapeを使って作成し、プレーンSVGとして保存)を使用しようとしています。私はsvg-android
ライブラリを使ってこれをしようとしています。 res/raw
にbackground.svg
というファイルがあります。私のコードは次のようになります。Androidでバックグラウンド描画可能なSVGを使用する
SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.background);
Drawable pictureDrawable = svg.createPictureDrawable();
Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(), pictureDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap);
LinearLayout backgroundLayout = (LinearLayout) findViewById(R.id.background);
bitmapDrawable.setTileModeX(Shader.TileMode.REPEAT);
backgroundLayout.setBackgroundDrawable(bitmapDrawable);
私のアプリケーションの起動時にただし、何も(レイアウトから背景色以外の)背景として現れません。次のように私のレイアウトxmlファイルは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#aacceeff"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/background"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
>
</LinearLayout>
</LinearLayout>
UPDATE
私のSVGに問題があることが表示されます。すべての機能がサポートされていないことが原因である可能性があります。
Drawable pictureDrawableをBitmapDrawableビットマップ描画の代わりにレイアウトの背景として設定しようとしましたか? –
@DimitrisMakrisはい、私が試した最初のことでしたが、まだ空白の背景があります。別の問題は、 'PictureDrawable'にタイリングを設定する方法がないことです。 –
ちょうど場合; - アンドロイドがSVGをネイティブにサポートしていないことを知っています Android用のFirefoxでコードをお試しください。 – Chasbeen