2015-08-31 52 views
0

我的应用程序的背景图像有问题,我已将其设置为android:background =“@ drawable/image_name”,并且在android studio的预览中,好,但是,当我运行应用程序,我看不到图像,但只有一个白色的背景,有人可以帮助我?Android,无法看到我的应用程序背景图像

,这里是我的xml

<RelativeLayout 
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" 
android:background="@drawable/splash" 
tools:context="com.example.ivan.posteggiaTI.LoginActivity"> 

<com.facebook.login.widget.LoginButton 
    android:id="@+id/login_button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:layout_above="@+id/editTextLoginEmail" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="48dp" /> 

<EditText 
    android:id="@+id/editTextLoginEmail" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/login_edit_text" 
    android:hint="Email" 
    android:inputType="textEmailAddress" 
    android:paddingBottom="0dp" 
    android:paddingLeft="15dp" 
    android:paddingRight="10dp" 
    android:paddingTop="0dp" 
    android:textColor="#000000" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginBottom="22dp" 
    android:layout_above="@+id/editTextLoginPassword" 
    android:layout_alignParentStart="true" /> 

<EditText 
    android:id="@+id/editTextLoginPassword" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/login_edit_text" 
    android:hint="Password" 
    android:inputType="textPassword" 
    android:paddingBottom="0dp" 
    android:paddingLeft="15dp" 
    android:paddingRight="15dp" 
    android:paddingTop="0dp" 
    android:textColor="#000000" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_above="@+id/textViewRegister" 
    android:layout_alignParentStart="true" 
    android:layout_marginBottom="34dp" /> 

<TextView 
    android:id="@+id/textViewRegister" 
    android:layout_width="160dp" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:background="@drawable/button_blue_login" 
    android:gravity="center_vertical|center_horizontal" 
    android:text="Registrati" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:textColor="#ffffff" 
    android:layout_alignTop="@+id/textViewLogin" 
    android:layout_toStartOf="@+id/textViewLogin" /> 

<TextView 
    android:id="@+id/textViewLogin" 
    android:layout_width="160dp" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:background="@drawable/button_blue_login" 
    android:gravity="center_vertical|center_horizontal" 
    android:text="Login" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:textColor="#ffffff" 
    android:layout_marginBottom="27dp" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentEnd="true" /></RelativeLayout> 
+1

尝试此代码,在我的设备上工作正常,棒棒糖 –

+0

尝试从代码更改背景代码像这里http://stackoverflow.com/questions/12523005/how-set-background-drawable-programmatically-in-android – DavidBalas

+0

哪个代码?你忘了它... –

回答

2

有时android studio不会在运行时安装新的apk。它将前面的活动放在前面。

按照步骤操作。

  1. 确保您在可绘制文件夹中有图像。
  2. 重建应用程序。 Build->重建应用程序
  3. 从模拟器或手机(测试设备)卸载应用程序。
  4. 运行该应用程序。

当您将图像放入可绘制文件夹中时。适当地选择你想要哪个图片的屏幕密度。

由于有drawable-ldpi,drawable-mdpi,drawable-hdpi等......和一个普通的可绘制文件夹。如果android studio无法在这些限定符可绘制文件夹中找到图像,那么它将在普通可绘制文件夹中查找。

+0

现在工作之前,非常感谢你许多 –

0

使用的ImageView为您RelativeLayout第一要素。然后,将您的drawable设置为ImageViewsrc,并将scaleType设置为fitXY,以便正确显示您的背景。

相关问题