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文件如下:@H_419_5@
<?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@H_419_5@
看来我的SVG有问题.这可能是因为不支持所有功能.@H_419_5@解决方法 svg-androID项目一年没有更新,它不支持SVG1.2,所以不支持Inkscape(开源)生成的svgs.
但是有一个新的androID svg库:AndroidSVG@H_419_5@
它们在版本1.2上,1.3的工作正在进行中.包括只是jar库可以在AndroID应用程序中编程地包含svgs.几乎所有的svg功能都包含在内.我还没找到一个无法使用这个库的svg.@H_419_5@
如果您在项目中将源代码(hg clone)中的androIDsvg作为库模块,您将获得SVGImageVIEw类,该类是ImageVIEw的扩展,您可以使用xml布局文件将svg添加到项目中:@H_419_5@
<com.caverock.androIDsvg.SVGImageVIEw xmlns:svg="http://schemas.androID.com/apk/res-auto" androID:layout_wIDth="100dp" androID:layout_height="50dp" svg:svg="filename.svg"/>
而已.所有你需要做的是将filename.svg放在资产文件夹中,你很好.@H_419_5@
它支持API 8及更高版本.将其用于API< 11但我能够解决这些问题.我将它们作为项目页面上的问题发布,作者在几分钟内作出回复.它们已经被添加到下一个版本.如果您有任何问题,请查看已解决的问题,否则我可以在这里回答问题. 附:项目页面上的文档和示例非常出色,图书馆很乐意与之合作. AndroID和svg是一个强大的组合.@H_419_5@ 总结
以上是内存溢出为你收集整理的在Android中使用SVG作为背景绘图全部内容,希望文章能够帮你解决在Android中使用SVG作为背景绘图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)