简体   繁体   English

背景可绘制项未在真实设备中显示

[英]Background drawable is not displaying in real device

Please have a look at the following XML 请看看以下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"
    tools:context=".MainActivity"
    android:background="@drawable/background_main" >
</RelativeLayout>

When I run this, all the tings are perfect and the background image of the main layout also get displayed in Emulator. 当我运行此命令时,所有的色彩都很完美,并且主布局的背景图像也显示在模拟器中。 But, when I run this code in Phone, the background image is missing! 但是,当我在Phone中运行此代码时,背景图片丢失了! What is wrong? 怎么了?

I found the issue by my self. 我自己发现了问题。 My app is multi screen supporting so I had to put those images (with different sizes) into all the related drawable folders. 我的应用程序支持多屏幕,因此我不得不将这些图像(大小不同)放入所有相关的可绘制文件夹中。

<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"
    tools:context=".MainActivity"
    android:background="@drawable/background_main" >

xmlns:tools are most probably used for the activity the tools UI editor uses to render your layout (it will find the right theme based on the activity). xmlns:tools最可能用于UI编辑器用来渲染布局的活动(它将根据活动找到正确的主题)。 So if you can just remove tools OR in .MainActivity java class. 因此,如果您只可以删除.MainActivity java类中的工具或。 define your background source. 定义背景源。

//outside your onCreate
RelativeLayout relativeLayout;
Context ctx;

//inside your onCreate
relativeLayout = new RelativeLayout(this);
relativeLayout.setBackgroundResource(R.drawable.background_main);
setContentView(relativeLayout);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM