添加背景图片到各个片段 [英] Add background image to individual fragments
问题描述
我有多个应用程序片段
,我想知道如何添加背景是每个片段$ C不同$ C>。我使用的布局有滚动的标签,所有使用相同的XML文件。我也有一个
MainActivity
,用于设置视图和适配器
每个片段
。我知道你可以使用XML文件中添加背景的android:背景
或诸如此类的东西,以及在主要活动将其设置为视图,但我不能弄清楚如何做给每个选项卡。感谢您的帮助!
I have an app with multiple fragments
and I would like to know how to add a background that is different for each fragment
. The layout I am using has scrollable tabs which all use the same xml file. I also have a MainActivity
that sets the view and an adapter
for each fragment
. I know you can add a background using the xml file with android:background
or something of the sort as well as setting it to the view in the main activity but I can't figure out how to do it to each tab. Thank you for any help!
推荐答案
要添加背景frangment,你必须包装在一些容器
To add background to frangment, you have to wrap it in some container
<LinearLayout
android:id="@+id/linearlayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ccc"
android:layout_weight="1"
android:orientation="vertical">
<fragment android:name="com.example.simplefragmentexample.LayOutOne"
android:id="@+id/frag_1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
如果您要使用相同的XML文件,你应该programaticly设置图像
LiniarLayout L =(LiniarLayout)findViewById(R.id.linearlayout01);
l.setBackground(图像);
If you which to use same xml file, you should set images programaticly LiniarLayout l = (LiniarLayout) findViewById(R.id.linearlayout01); l.setBackground(Image);
或使用多个XML的采用Android:背景
or use several xmls with android:background
这篇关于添加背景图片到各个片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!