Android 重用Layout


<include> tag basically means ‘take that file and paste it’s contents here’

<merge > The layout which we have to use must be enclosed under merge tag, so that we can include layouts from other xmls.

[u][/u]
<merge xmlns:android="http://schemas.android.com/apk/res/android">
	<LinearLayout android:id="@+id/LinearLayout01"
		android:layout_width="wrap_content" android:layout_height="wrap_content">
		<Button android:layout_width="wrap_content"
			android:layout_height="wrap_content" android:id="@+id/Button11"
			android:text="Button11"></Button>
		<Button android:layout_below="@id/Button01"
			android:layout_width="wrap_content" android:layout_height="wrap_content"
			android:id="@+id/Button12" android:text="Button12"></Button>
	</LinearLayout>
</merge>


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
	android:layout_width="fill_parent" android:layout_height="fill_parent"
	xmlns:android="http://schemas.android.com/apk/res/android">
	<RelativeLayout android:id="@+id/RelativeLayout02"
		android:layout_width="wrap_content" android:layout_height="wrap_content"
		android:layout_centerInParent="true">
		<Button android:id="@+id/Button01" android:layout_width="wrap_content"
			android:layout_height="wrap_content" android:text="Next Activity   "></Button>
	</RelativeLayout>
	<RelativeLayout android:id="@+id/RelativeLayout03"
		android:layout_width="wrap_content" android:layout_height="wrap_content"
		android:layout_alignParentBottom="true">
		<include layout="@layout/footer" />
	</RelativeLayout>
</RelativeLayout>


public class Splash extends Activity implements OnClickListener {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		findViewById(R.id.Button01).setOnClickListener(this);
		findViewById(R.id.Button11).setOnClickListener(this);
		findViewById(R.id.Button12).setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.Button01:
			startActivity(new Intent(this, Act2.class));
			break;
		case R.id.Button11:
			Toast.makeText(this, "Button 11 - Activity 1 ....",
					Toast.LENGTH_SHORT).show();
			break;
		case R.id.Button12:
			Toast.makeText(this, "Button 12 - Activity 1 ....",
					Toast.LENGTH_SHORT).show();
			break;
		}
	}

}


You can download its complete source code from here . http://www.megaupload.com/?d=XZ3KTOGI

猜你喜欢

转载自jacky-zhang.iteye.com/blog/1677667