我的应用程序停止在设置Relativelayout背景上工作

时间:2018-02-17 07:24:17

标签: android android-relativelayout

当将图像作为背景放在相对布局中时,应用程序无法在设备中工作,尽管它在所有模拟中工作 - 图像大小630 * 354 JPEG

<?xml version="1.0" encoding="utf-8"?>
<Relativelayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools: context="com.a7mad7assan.telwat.MainActivity"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/mini" >
</Relativelayout>

enter image description here

1 个答案:

答案 0 :(得分:0)

除了将图像变成九个补丁外,我不认为这是可能的。您可以做的是添加ImageView作为RelativeLayout中的第一个视图。将layout_centerInParent设置为true并将layout_width和layout_height设置为match_parent。然后将scaleType设置为centerCrop。这将确保图像填充屏幕而不会出现任何失真,但根据屏幕尺寸/方向,图像的顶部/底部或左/右部分可能会被切断。

<ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerInParent="true" android:scaleType="centerCrop" android:src="@drawable/background" />

RelativeLayout中的任何其他视图都会出现在ImageView的顶部,只要它是RelativeLayout中的第一个视图(当你在xml中时)。