2012-01-18 36 views
0

我想在我的应用程序上运行多个活动;我希望每个活动都具有线性布局并将图像显示为标题;基本上我想每一个布局,像这样开头:避免重写具有相同布局的活动的代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@color/Grey" 
> 
<ImageView android:id="@+id/imageHeader" android:src="@drawable/tf_header" android:layout_height="wrap_content" android:layout_width="fill_parent" 
    android:background="@color/Black" android:scaleType="fitXY"></ImageView> 

是否有可能不reapeat为每个布局这个代码?我可以使用主题或样式来避免它吗?谢谢您的回复。

回答

2

是的,可以使用<include>标签,如Layout Tricks中所述。

为了您的例子,我想补充的形象<include>并在每个活动布局XML格式的LinearLayout

0

我的一个应用程序使用了30个左右的类别相同的XML文件,我只是修改代码来定制它。这种方法可能会起作用,只需将每个标签留在xml空白处并将其设置在.class