在视图中调整SVG图像的大小 [英] Resize SVG image inside View

查看:291
本文介绍了在视图中调整SVG图像的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有SVG图像的FloatingActionButton绑定到它的src属性.但是它没有查看我需要的大小,如何调整它的大小以显示更大的图像?

I have a FloatingActionButton with a SVG image binded to it's src property. But It doesn't view the size I need, How to resize it to show the image bigger?

这是我的可绘制对象:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">
<path
    android:fillColor="#ffffff"
    android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>

这是我的观点:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/ic_add_24dp" />

推荐答案

支持Vector Drawables和Animated Vector Drawables 通过矢量可绘制对象,您可以用XML中定义的单个矢量图形替换多个png资产.虽然以前只限于棒棒糖和更高版本的设备,但现在VectorDrawableAnimatedVectorDrawable都可以分别通过两个新的支持库support-vector-drawable和animation-vector-drawable获得.

Support Vector Drawables and Animated Vector Drawables Vector drawables allow you to replace multiple png assets with a single vector graphic, defined in XML. While previously limited to Lollipop and higher devices, both VectorDrawable and AnimatedVectorDrawable are now available through two new Support Libraries support-vector-drawable and animated-vector-drawable, respectively.

Android Studio 1.4通过在构建时生成png引入了对向量drawables的有限支持.要禁用此功能(并获得此支持库的真正优势和节省空间),您需要在build.gradle文件中添加vectorDrawables.useSupportLibrary = true:

Android Studio 1.4 introduced limited support for vector drawables by generating pngs at build time. To disable this functionality (and gain the true advantage and space savings of this Support Library), you need to add vectorDrawables.useSupportLibrary = true to your build.gradle file:

// Gradle Plugin 2.0+

 android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
    }  
 }   

您会注意到,此新属性仅存在于Gradle插件的2.0版中.如果您使用的是Gradle 1.5,则改为使用

You’ll note this new attribute only exists in the version 2.0 of the Gradle Plugin. If you are using Gradle 1.5 you’ll instead use

// Gradle Plugin 1.5

 android {  
   defaultConfig {  
     generatedDensities = []  
  }  

  // This is handled for you by the 2.0+ Gradle Plugin  
  aaptOptions {  
    additionalParameters "--no-version-vectors"  
  }  
 } 

然后在您的xml布局中添加此代码app:srcCompat="@drawable/ic_add".类似于此代码:

And your xml layout add this code app:srcCompat="@drawable/ic_add" .Like this code :

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@drawable/ic_add_24dp" />

有用的链接支持矢量可绘制对象和动画矢量可绘制对象

这篇关于在视图中调整SVG图像的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆