我在 android 中使用 SVG 导入图像,但我无法使用 ImageView 调整它的大小,图像是这样的。
导入的drawable是:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="208dp"
android:height="208dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#8A1D3043"
android:pathData="...lines and curves..."/>
</vector>
当我更改 ImageView(它附加到的位置)layout_height 和 layout_width 时,我得到:
<ImageView
android:layout_height="100dp"
android:layout_width="100dp"
app:layout_width="@{smallScreen ? @dimen/img_small_screen_size : @dimen/img_big_screen_size}"
app:layout_height="@{smallScreen ? @dimen/img_small_screen_size : @dimen/img_big_screen_size}"
android:layout_gravity="center_horizontal"
android:contentDescription="@{message}"
android:src="@{image}"
android:scaleType="center"
tools:src="@drawable/img_message_private"/>
注意vector的高和宽都是208dp,但是我的ImageView必须是100dp。我认为必须使用 dataBind 动态调整 View 的大小,因此不能选择多个向量。
显然,图像不会随其 ImageView 缩放。有人知道为什么以及如何轻松绕过它吗?
最佳答案
问题出在线路上:
android:scaleType="center"
Here's a link to the documentation在哪里你可以看到这个的定义:
Center the image in the view, but perform no scaling.
尝试使用另一种 scaleType,例如:
android:scaleType="fitCenter"
关于android - Android 中的矢量动态调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34866956/