我的应用背景不会填满屏幕
问题描述:
如何让我的背景图像填满整个屏幕?我尝试了几个不同的建议,似乎没有任何工作。我的应用背景不会填满屏幕
下面是我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>
答
解决方案一:
你可以把layout_width
和你ImageView
到match_parent
的layout_height
:
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="@drawable/background_flat_720x1280" />
解决方法二:
您可以在ConstraintLayout
直接设置背景(不要忘记删除ImageView
):
<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"
android:background="@drawable/background_flat_720x1280"
tools:context="com.andrewvanpeter.upandaway.MainActivity">
答
您还可以设置的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" />
+0
工作。谢谢 – CheetahBongos
match_parent解决方案无法正常工作;也许我在做别的事情。但是,直接设置背景确实奏效。非常感谢你! – CheetahBongos
没问题,很高兴!也许你在某处有填充或边距...或者你必须适合ImageView。 –