Java 如何在Android Studio中消除NoActionBar和ImageView之间的差距

Java 如何在Android Studio中消除NoActionBar和ImageView之间的差距,java,android,xml,android-studio,adobe-xd,Java,Android,Xml,Android Studio,Adobe Xd,如何在约束图中消除此间隙?顶部是一个图像视图,其顶部约束位于父视图的顶部(ConstraintLayout) 工具栏和横幅之间顶部的间隙 以下是my styles.xml的外观: <resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your t

如何在约束图中消除此间隙?顶部是一个图像视图,其顶部约束位于父视图的顶部(ConstraintLayout)

工具栏和横幅之间顶部的间隙

以下是my styles.xml的外观:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音

我的activity_main.xml如下所示:

<?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=".MainActivity">

    <ImageView
        android:id="@+id/headerImg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/header" />

    <Button
        android:id="@+id/addlog_btn"
        style="@android:style/Widget.DeviceDefault.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginTop="108dp"
        android:background="@drawable/newlogbtn"
        android:fontFamily="@font/roboto_regular"
        android:onClick="createNewLog"
        android:paddingTop="72sp"
        app:layout_constraintStart_toStartOf="@+id/headerImg"
        app:layout_constraintTop_toTopOf="@+id/headerImg" />

    <Button
        android:id="@+id/addlog_btn2"
        style="@android:style/Widget.DeviceDefault.Button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="32dp"
        android:layout_marginRight="32dp"
        android:background="@drawable/settingsbtn"
        android:fontFamily="@font/roboto_regular"
        android:paddingTop="72sp"
        app:layout_constraintEnd_toEndOf="@+id/headerImg"
        app:layout_constraintTop_toTopOf="@+id/addlog_btn" />
</androidx.constraintlayout.widget.ConstraintLayout>


如果可能的话,我想通过编辑XML来实现这一点,我试图更改两个父级的边距和填充,但我做得不对,或者似乎不起作用。

您可以通过添加android:scaleType=“centerCrop”来消除这一差距
到横幅
图像视图
,这样它将填满整个指定的房间

因此,布局将在此更改之后:

<?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=".MainActivity">

    <ImageView
        android:id="@+id/headerImg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/header" />

    <Button
        android:id="@+id/addlog_btn"
        style="@android:style/Widget.DeviceDefault.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginTop="108dp"
        android:background="@drawable/newlogbtn"
        android:fontFamily="@font/roboto_regular"
        android:onClick="createNewLog"
        android:paddingTop="72sp"
        app:layout_constraintStart_toStartOf="@+id/headerImg"
        app:layout_constraintTop_toTopOf="@+id/headerImg" />

    <Button
        android:id="@+id/addlog_btn2"
        style="@android:style/Widget.DeviceDefault.Button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="32dp"
        android:layout_marginRight="32dp"
        android:background="@drawable/settingsbtn"
        android:fontFamily="@font/roboto_regular"
        android:paddingTop="72sp"
        app:layout_constraintEnd_toEndOf="@+id/headerImg"
        app:layout_constraintTop_toTopOf="@+id/addlog_btn" />
</androidx.constraintlayout.widget.ConstraintLayout>


请添加布局xml。@如果您发现答案有帮助,请点击左侧的勾号接受。。谢谢