gpt4 book ai didi

android - Android 中的矢量动态调整大小

转载 作者:行者123 更新时间:2023-11-29 14:46:36 24 4
gpt4 key购买 nike

我在 android 中使用 SVG 导入图像,但我无法使用 ImageView 调整它的大小,图像是这样的。

enter image description here

导入的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"/>

enter image description here

注意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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com