android - 不可能使用 android 中的约束布局将图像放在顶部
问题描述
我试图将图像标题放在约束布局的顶部但是当我在真实设备中运行应用程序时它是错误的并且标题不在顶部:
<?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/header"
android:layout_width="0dp"
android:layout_height="207dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_header" />
</androidx.constraintlayout.widget.ConstraintLayout>
下面我们可以看到它在真实设备中的外观:
操作栏和标题之间有一个空格。我试图删除操作栏但也不起作用。提前致谢。
这是我的 ic_header 内容:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="360dp"
android:height="180dp"
android:viewportWidth="360"
android:viewportHeight="180">
<path
android:pathData="M0,0h360v180h-360z"
android:fillColor="#fbc711"/>
</vector>
解决方案
I think the issue is with the src drawable and the ImageView
both having a fixed height.
Try using android:scaleType="centerCrop"
in your ImageView
xml, so that the source image expands to cover the empty area.
推荐阅读
- javascript - 如何在 JavaScript 中单击 5 次图像时发生事件?
- php - 每个帖子中打印描述的php代码?
- timer - Paho MQTT 通过重置设置延迟
- cypher - 在where条件下未绑定节点上的AgensGraph语法错误
- java - 黄瓜与 JUnit java.lang.ExceptionInInitializerError
- javascript - 警告:ngModel 在与 formControlName 相同的表单字段上
- swift - 我无法将 UIBezierPath 添加到 CAEmitterCell 的内容变量
- r - 在没有互联网的centos 7上安装stringi
- reactjs - 如何在 nextjs 打字稿中动态导入函数?
- r - Groupby R中的多列