在 constraintView 中为 imageView 设置 minHeight 不起作用

Setting minHeight for an imageView within a constraintView not working

我一段时间以来第一次开发 Android 应用程序并尝试使用约束布局,因为我需要不同 phone 尺寸的屏幕。

我将页面中的元素链接在一起,因此它们都相互关联,但是在顶部 imageView 上设置 minHeight 不起作用。图像被其他元素挤压。我需要蓝色按钮更小,图片更突出。

此外,我使用的按钮图像被裁剪成准确的图像,但是当我将它们添加到视图时图像有边距,我不明白这一点。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:id="@+id/home_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/topLogo"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toTopOf="@+id/keyVisual"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/toplogo" />

    <ImageView
        android:id="@+id/keyVisual"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginStart="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginEnd="32dp"
        android:layout_marginRight="32dp"
        app:layout_constraintBottom_toTopOf="@id/homeText"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/topLogo"
        app:srcCompat="@drawable/keyvisual" />

    <TextView
        android:id="@+id/homeText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginTop="24dp"
        android:layout_marginEnd="32dp"
        android:layout_marginRight="32dp"
        android:layout_marginBottom="24dp"
        android:text="@string/hometext"
        app:layout_constraintBottom_toTopOf="@id/startButton"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/keyVisual" />



    <ImageView
        android:id="@+id/startButton"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginStart="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:layout_marginEnd="32dp"
        app:layout_constraintBottom_toTopOf="@id/langButton"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/homeText"
        app:srcCompat="@drawable/startbutton" />

    <ImageView
        android:id="@+id/langButton"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginStart="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginEnd="32dp"
        android:layout_marginRight="32dp"
        app:layout_constraintBottom_toTopOf="@id/tabBar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/startButton"
        app:srcCompat="@drawable/startbutton" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/langButton">

        <android.support.design.widget.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Monday" />

        <android.support.design.widget.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Tuesday" />

        <android.support.design.widget.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Wednesday" />
    </android.support.design.widget.TabLayout>

</android.support.constraint.ConstraintLayout>

您可以使用这些属性使您的图像尺寸响应:

app:layout_constraintHeight_percent="0.25"
app:layout_constraintWidth_percent="0.25"

它将告诉您的图像在高度和宽度上都等于屏幕尺寸的 1/4,这样您的图像将适合所有屏幕尺寸。

I think there should be Code android:background="@drawable/startbutton" instead of app:srcCompat="@drawable/startbutton" then your problem is Solve.

And I have a suggestion that do not use app:srcCompat="@drawable/startbutton" again to apply the image, but use android:src="@drawable/startbutton" instead.