白色填充/边框

9vw9lbht  于 2021-08-20  发布在  Java
关注(0)|答案(3)|浏览(414)

我第一次在设备上安装了我的应用程序。它在emulator上工作得很好,但是现在它的边缘有了白色的填充物,这会影响透明按钮的位置(参见屏幕截图)。我想知道是否有办法迫使整个图像占据整个屏幕,并删除侧面的白色。请告诉我您的最佳解决方案。

谢谢

<?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"
    tools:context=".firstroom">

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/firstroom" />
</androidx.constraintlayout.widget.ConstraintLayout>
2cmtqfgy

2cmtqfgy1#

你可以用 android:scaleType="centerCrop"android:scaleType="fitXY" 在您的图像视图中。
我还建议您浏览以下链接:https://thoughtbot.com/blog/android-imageview-scaletype-a-visual-guide

r1wp621o

r1wp621o2#

您可以使用imageview标记中的“scaletype”属性

android:scaleType="centerCrop"

android:scaleType="fitXY"

还有其他一些类型。如下图所示

nkoocmlb

nkoocmlb3#

您必须使用该属性 android:scaleType .
如果要保持纵横比不变,则必须使用 android:scaleType="centerCrop" ,这将使图像居中于imageview,并保持纵横比进行缩放。因此,如果需要,它可以裁剪宽度或高度的某些部分。

<ImageView
    android:scaleType="centerCrop"
    android:id="@+id/imageView2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/firstroom" />

如果不想保持纵横比,则必须使用 android:scaleType="fitXY" ,这将缩放高度和宽度以将图像填充到imageview。因此,图像可能会水平或垂直拉伸。

<ImageView
    android:scaleType="fitXY"
    android:id="@+id/imageView2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/firstroom" />

有关更多信息,请参阅官方文件。

相关问题