SVGImageView

简介:

In essence, I'm trying to layer multiple ImageViews (one of which is a floor plan, the other a rectangle) on top of each other while still allowing for pinch-zooming. The effect I'm going for is very similar to this post: http:/ /stackoverflow.com/questions/10482229/draw-rectangle-over-imageview-for-highlight-that-can-be-zoom-in-out-in-android?rq=1. However, I want the rectangle to appear at application startup (as opposed to when the user taps the screen) and to update its position over time.

One of my images is an SVG file of a floor plan. I'm using the AndroidSVG library (https:/ /code.google.com/p/androidsvg/) to render it to Android as an SVGImageView. My current implementation allows for pinch-zooming and panning of this SVG file (on application startup: http:/ /imgur.com/SceJuni; after pinch-zooming: http:/ /imgur.com/wL8anKd).

(Sorry for the space in the links; I don't have 10 reputation points so I can't post more than one link)

Now I need to overlay this SVGImageView with a rectangle to denote a location on this map. I want this rectangle to zoom in and out as the SVGImageView zooms in and out. I considered using the ScaleImageView class from this link (https:/ /github.com/matabii/scale-imageview-android) but now I am unsure how to proceed.

Here's the repo: https://github.com/mthai95/SVGApp

And heres what I have so far:

复制代码
import android.app.Activity;
import android.graphics.*;
import android.os.Bundle;
import android.util.FloatMath;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.caverock.androidsvg.SVGImageView;

public void onCreate(Bundle savedInstanceBundle) {
    super.onCreate(savedInstanceState);
    LinearLayout layout = new LinearLayout(this);
    SVGImageView svgImageView = new SVGImageView(this);
    svgImageView.setImageAsset("w1a.svg");
    svgImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    svgImageView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ... pinch-zoom and pan ...
        }
    });
    layout.addView(svgImageView,
            new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    setContentView(layout);
}
复制代码

 

上图的svg为:

复制代码
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 15.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     width="140px" height="140px" viewBox="0 0 140 140" enable-background="new 0 0 140 140" xml:space="preserve">
<style type="text/css">
<![CDATA[
    .strokeColor{fill:#DB3E38;}      //样式
]]>
</style>
<g>
    <path class="strokeColor" d="M128.877,63.448c0.281,2.34,0.441,4.715,0.441,7.129c0,32.614-26.375,59.053-58.907,59.053
        c-32.534,0-58.908-26.438-58.908-59.053s26.374-59.052,58.908-59.052c18.292,0,34.637,8.358,45.44,21.472
        c2.896-0.342,6.056-1.781,6.443-6.324C109.839,11.895,91.225,2.5,70.411,2.5C32.904,2.5,2.5,32.979,2.5,70.577
        c0,37.599,30.404,68.077,67.911,68.077c37.506,0,67.911-30.479,67.911-68.077c0-2.656-0.168-5.273-0.465-7.852
        C135.914,61.223,132.539,59.778,128.877,63.448z"/>                  //环形的线
    <rect x="41.911" y="65.911" class="strokeColor" width="58.667" height="7.666"/>     //横着的线
    <rect x="67.411" y="40.411" class="strokeColor" width="7.667" height="58.667"/>     //竖着的线
</g>
</svg>
复制代码

 由于绘制路径的复杂性,因此强烈建议您使用 SVG 编辑器来创建复杂的图形。


本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/5438776.html,如需转载请自行联系原作者

相关文章
|
XML Android开发 数据格式
android中SVG 的使用姿势
android中SVG 的使用姿势
1350 0
android中SVG 的使用姿势
快速生成软著申请时所需的60页代码文档的免费工具
本篇文章主要讲解,制作软著代码文档的高效方法,当然不可能手动一个个复制了,这显然太笨拙,他浪费时间了。这里我给大家介绍一个更快的方式。
7429 0
|
Java
Mac下安装JDK11(国内镜像)
Mac下安装JDK11(国内镜像)
7199 0
|
Go iOS开发 MacOS
手把手教你在Mac上从零搭建Go语言开发环境
手把手教你在Mac上从零搭建Go语言开发环境
4629 0
|
Android开发
Android--在非activity弹出Dialog对话框
版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/80521795 需要在adapter类监听button点击事件弹出需要弹出一个系统级对话框,也就是这个对话框不论是在哪个活动,都可以弹出这个对话框。
3383 0
|
6天前
|
人工智能 运维 安全
|
4天前
|
人工智能 异构计算
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
|
5天前
|
机器学习/深度学习 人工智能 自然语言处理
B站开源IndexTTS2,用极致表现力颠覆听觉体验
在语音合成技术不断演进的背景下,早期版本的IndexTTS虽然在多场景应用中展现出良好的表现,但在情感表达的细腻度与时长控制的精准性方面仍存在提升空间。为了解决这些问题,并进一步推动零样本语音合成在实际场景中的落地能力,B站语音团队对模型架构与训练策略进行了深度优化,推出了全新一代语音合成模型——IndexTTS2 。
558 17