ImageView在RelativeLayout内未显示完整高度

问题描述 投票:0回答:3
<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,但它也不起作用。如何正确显示图像的高度?

enter image description here

android imageview android-relativelayout
3个回答
0
投票

删除此行

android:layout_centerInParent =“ true” android:scaleType =“ fitXY”


0
投票

我希望使用如下所示的约束布局,而不是相对布局

<?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>

0
投票
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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_height="match_parent"
    android:layout_width="match_parent"
    tools:context=".MainActivity">

<ImageView
   android:id="@+id/image"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:scaleType="fitXY"
   android:src="@drawable/snake"
  />

© www.soinside.com 2019 - 2024. All rights reserved.