我有一个floatingActionButton,它的src属性绑定了一个SVG图像。但它看不到我需要的大小,如何调整它显示图像更大?
这是我的抽屉:

<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允许您用XML定义的单个矢量图形替换多个PNG资源。虽然以前仅限于棒棒糖和更高的设备,VectorDrawableAnimatedVectorDrawable现在都可以通过两个新的支持库分别支持向量drawable和动画向量drawable。
android studio 1.4通过在构建时生成png,引入了对vectordrawables的有限支持。要禁用此功能(并获得此支持库的真正优势和空间节省),需要将vectorDrawables.useSupportLibrary = true添加到build.gradle文件中:

// Gradle Plugin 2.0+

 android {
   defaultConfig {
     vectorDrawables.useSupportLibrary = true
    }
 }

您将注意到这个新属性只存在于Gradle插件的2.0版本中。如果你用的是1.5级,你会用
// Gradle Plugin 1.5

 android {
   defaultConfig {
     generatedDensities = []
  }

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

您的XML布局添加了这段代码。
<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" />

有用链接 Support Vector Drawables and Animated Vector Drawables

08-05 03:06
查看更多