Java ANDROID STUDIO-布局背景(图像)不';不显示
各位,首先,我的android项目有一个问题。我将图像设置为具有适当宽度(5.5)的布局背景,当我运行应用程序时,它显示为白色背景,而不是预期的图像。图像位于drawable文件夹中,一切正常 图像具有与布局相同的尺寸(5.5) 代码:Java ANDROID STUDIO-布局背景(图像)不';不显示,java,android-studio,android-layout,Java,Android Studio,Android Layout,各位,首先,我的android项目有一个问题。我将图像设置为具有适当宽度(5.5)的布局背景,当我运行应用程序时,它显示为白色背景,而不是预期的图像。图像位于drawable文件夹中,一切正常 图像具有与布局相同的尺寸(5.5) 代码: 如果要加载整个图像,我会在布局的根视图组中使用ImageView,将两个维度设置为match\u parent 这将解决图像无法加载的问题,同时还可以定义缩放类型(如centerCrop),这使您可以拥有任意边长比的图片,并确保它可以垂直和水平填充屏幕 编辑:
如果要加载整个图像,我会在布局的根视图组中使用
ImageView
,将两个维度设置为match\u parent
这将解决图像无法加载的问题,同时还可以定义缩放类型(如centerCrop
),这使您可以拥有任意边长比的图片,并确保它可以垂直和水平填充屏幕
编辑:
提议的解决办法:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
tools:context=".MainActivity">
<ImageView
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/fundo" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_marginTop="200dp"
app:srcCompat="@drawable/logo_branco" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="450dp"
android:fontFamily="@font/advent_pro_thin"
android:text="O automóvel ideal para si!"
android:textColor="#E76C00"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
您可以添加绘图吗?看起来xml代码没有任何问题,为了获得更好的结果,请共享您的背景图像添加完整的.xml
文件,也许有人可以帮助您。说明更新!!我可以拿出一个gradient.xml作为背景,但是图像我做不到…首先感谢你的帮助!我试过了,但不幸的是没有成功我很高兴你解决了它!你知道最初的图像有什么问题吗?您好,我想问题是图像的分辨率,可能是我的手机在运行应用程序时无法处理相同的图像!非常感谢。