android - ImageView 在 RelativeLayout 内不显示全高
问题描述
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Gray">
<ImageView
android:id="@+id/ImgView"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
图像实际比例为 360/640,但目前显示为 1:1,图像高度显示不正确。我试图将图像视图 layout_height 设置为 wrap_content 但它也不起作用。如何正确显示图像的高度?
解决方案
我更喜欢使用如下所示的约束布局而不是相对布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Gray"
android:type="radial"
>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo" />
</androidx.constraintlayout.widget.ConstraintLayout>
推荐阅读
- c - 如何在 Mac 上搜索、安装和包含/链接 C 库?
- mysql - 如何优化带有未索引日期列的 Sql 查询?
- python - 解释 1 行 C 代码并将其翻译成 Python
- sdl-2 - 纹理出现在错误的表面 SDL2
- java - 无法解析 ':app@debug/compileClasspath' 的依赖关系:无法解析 com.sensortower.usage:event-emitter-lib:1.0.0
- putty - 是否有 putty 命令来检查生成的数据通道?
- mongodb - MongoDB - 具有数字范围的 elemMatch 不能按预期工作?
- google-play - Google 位置权限政策中的“内容上下文”是什么?
- javascript - 如何从angularjs中的控制器动态加载css和js文件
- grafana - graphana中的错误计算