在顶部移动图像视图

moving imageview at top

我有一张尺寸为 519px X 420px 的图像,我想将其放置在 android 屏幕的顶部。现在我的图像和我想要完全删除的 header 之间有一些空白 space。

XML代码:

<ImageView
android:src="@drawable/sitemakers_laptops"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

请查看上面的屏幕截图并帮助我以这种方式更新我的 XML,以便蓝色 header 和图像之间的空白 space 完全消失。

提前致谢!

按要求完成 XML 代码:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="in.sitemakers.sitemakers.AboutFragment">

<ImageView
    android:src="@drawable/sitemakers_laptops"
    android:layout_width="match_parent"
    android:scaleType="fitXY"
    android:layout_height="wrap_content" />

</FrameLayout>

试试这个 ImageView.ScaleType

Options for scaling the bounds of an image to the bounds of this view.

使用android:scaleType="fitXY"

    <ImageView
    android:src="@drawable/sitemakers_laptops"
    android:layout_width="match_parent"
    android:scaleType="fitXY"
    android:layout_height="wrap_content" />

试试这个 ImageView.ScaleType

Options for scaling the bounds of an image to the bounds of this view.

Use android:scaleType="fitXY"

Scale the image using FILL.

<ImageView
    android:src="@drawable/sitemakers_laptops"
    android:layout_width="match_parent"
    android:scaleType="fitXY"
    android:layout_height="420dp" />

更新了 XML 用于在 header 之后发布图片的代码。我们必须给出图像的静态高度以及 android scaleType

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="in.sitemakers.sitemakers.AboutFragment">

    <ImageView
       android:src="@drawable/sitemakers_laptops"
       android:layout_width="match_parent"
       android:scaleType="fitXY"
       android:layout_height="420dp" />

</FrameLayout>

您可以使用android:scaleType="fitXY"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
orientation="vertical"
android:layout_height="match_parent">

<ImageView
    android:src="@drawable/sitemakers_laptops"
    android:layout_width="match_parent"
    android:scaleType="fitXY"
    android:layout_height="wrap_content" />

</LinearLayout>