android - Android:在ConstraintLayout中保持全宽和未定义高度ImageView的比例?
问题描述
在 aConstraintLayout
中,an 以ImageView
如下方式绑定到其父级:
它的左侧绑定到屏幕的左侧
它的右侧绑定到屏幕的右侧
它的顶部绑定到小部件的底部
它的底边绑定到屏幕的底边
因此 myImageView
似乎是全角的,它的高度是小部件与屏幕底部之间的距离。
<ImageView
android:id="@+id/imageView16"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
android:background="@drawable/ic_background_stars"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/linearLayout4"
app:layout_constraintBottom_toBottomOf="parent"
/>
问题是它包含的 SVG 也是全宽的,但比例已被破坏:就高度而言,它不够大。所以SVG是扭曲的。
问题
如何以全宽显示 SVG(从屏幕左侧到右侧),同时保持其比例(使其高度足够大)?
解决方案
除了最后一个答案之外,您的图像未正确缩放的原因是因为您将其用作背景。
你的代码..
android:background="@drawable/ic_background_stars"
相反,将其用作图像资源。
app:srcCompat="@drawable/ic_background_stars"
ImageView 的默认比例类型应该为您完成工作。否则,您甚至可以尝试各种规模类型。
推荐阅读
- go - Golang 无法导入分叉的存储库
- c++ - 我在 C++ 中将浮点变量转换为字符串时遇到问题
- java - 解析带有小数和分组分隔符的货币字符串,或者如果 Pattern 不匹配则抛出
- java - 无法反转单链表实现的队列中的前 k 个元素
- amazon-web-services - 安装提供程序“aws”时出错:openpgp:未知实体的签名
- java - 通过将日期时间连接到 Multipart 文件的名称来替换它不能正常工作
- python-3.x - python:与 mpi4py 联合进行多处理
- javascript - 如何仅在 v-html 元素中呈现锚标记并避免其他标记并将它们显示为字符串
- javascript - 如何在 AWS Analytics 中捕获用户的位置
- docker - 如何获取当前主机上 Docker swarm 全局服务的地址?