2013-03-08 170 views
0

我在我的应用程序中使用片段,我必须更改FragmnetTabs中片段之一的背景。由于这个原因,我设置了background这个fragmnet的布局,我可以在Graphical LayoutEclipse看到工作正常。但是当我运行我的应用程序时,它向我显示带有黑色背景的片段内容,而不是我设置的图像。我正在这样设置...为片段设置背景?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/bg" > 
<RelativeLayout/> 

但是这个drwaable没有显示在应用程序中。可能是什么问题呢?任何帮助表示赞赏。谢谢!

编辑:

如果我尝试设置背景通过以下方式,它工作正常。

 android:background="@drawable:color/anycolor" 

为什么自定义图像没有显示出来,但Android的颜色呢?

+0

@Marco的XML是相同的,我已经发布。我的意思是它不完整......但它在屏幕上的主要布局。 – 2013-03-08 22:55:13

回答

1

您可以尝试在代码中执行此操作。请拨打RelativeLayout

yourRelativeLayout.setBackground(getActivity().getResources().getDrawable(R.drawable.YourImage));