You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio中如何消除ImageView与屏幕/父布局间的额外间距?

问题:移除ImageView顶部的额外间距

我正尝试移除应用页面顶部作为横幅的ImageView上方存在的额外间距,只有将该ImageView设置为全屏时,间距才会消失。我已尝试修改ScaleType等方法仍未解决,特此求助。


ImageView的XML代码(使用ConstraintLayout布局)

<ImageView
        android:id="@+id/pagebanner"
        android:layout_width="match_parent"
        android:layout_height="110dp"
        android:background="@drawable/bannerborder"
        android:contentDescription="@string/page_banner"
        app:layout_constraintBottom_toTopOf="@+id/guideline8"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

ImageView使用的drawable(bannerborder)代码

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <solid android:color="@color/colorPurple" />
</shape>

已尝试的解决方案

  • 将ScaleType修改为fitXY及其他所有选项
  • 尝试过将adjustViewBoundaries设置为true和false
  • 尝试使用负布局边距

内容的提问来源于stack exchange,提问作者C James

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 03:23:11