这里呢我想实现的功能就是屏幕上方是一个固定的logo标识,下方呢是不同的控件,而且多个屏都要使用同一个logo
为了节省资源使用merge
public View getCommonLayout(LayoutInflater inflater, int contentLayout){
LinearLayout commonLyt = (LinearLayout)inflater.inflate(R.layout.lay_common, null);
inflater.inflate(contentLayout, commonLyt,true);
ImageView logo = (ImageView) commonLyt.findViewById(R.id.Logo);
logo.setBackgroundResource(getLogo());
return commonLyt;
}
R.layout.lay_common
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center_horizontal"
android:background="@drawable/smoke40">
<ImageView android:id="@+id/Logo" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="20px"
android:layout_marginBottom="10px" />
</LinearLayout>
上面呢就是建立了一个屏幕上方的logo
然后就可以加载其他的了
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
setContentView(getCommonLayout(inflater,R.layout.lay_content_main));
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center_horizontal">
<Spinner android:id="@+id/TypeSpinner" android:layout_width="wrap_content"
android:layout_height="wrap_content" style="@layout/cigar_row" />
<Button android:id="@+id/SaveButton" android:text="Save"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<Button android:id="@+id/ViewListButton" android:text="View List"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<CheckBox android:id="@+id/olvidado" android:text="Se me olvido"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:clickable="true" />
<TimePicker android:id="@+id/CuandoFumadoPicker"
android:visibility="gone" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:id="@+id/DevelopingButton" android:text="Developing"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</merge>