我的应用背景不会填满屏幕

时间:2017-12-02 20:20:12

标签: android layout imageview

如何让背景图像填满屏幕?我尝试了几种不同的建议,似乎没有任何效果。

enter image description here

以下是我的activity_main.xml的代码:

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.andrewvanpeter.upandaway.MainActivity">

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/background_flat_720x1280" />

</android.support.constraint.ConstraintLayout>

2 个答案:

答案 0 :(得分:1)

第一个解决方案:

您可以将layout_width的{​​{1}}和layout_height添加到ImageView

match_parent

第二个解决方案:

您可以直接在<ImageView android:id="@+id/imageView2" android:layout_width="match_parent" android:layout_height="match_parent" app:srcCompat="@drawable/background_flat_720x1280" /> 设置背景(不要忘记删除ConstraintLayout):

ImageView

答案 1 :(得分:1)

你也可以将imageview的scaletype设置为fitXY,如下所示:

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"
    app:srcCompat="@drawable/background_flat_720x1280" />