編輯:初級開發
有三個布局文件和三個Activity
menu1 的布局文件-main.XML:
vIEw plaincopy to clipboardprint?
01.<?XML version="1.0" encoding="UTF-8"?>
02.<RelativeLayout XMLns:android="http://schemas.android.com/apk/res/android"
03. android:layout_width="fill_parent"
04. android:layout_height="wrap_content">
05. <!-- 菜單one -->
06. <ImageVIEw
07. android:id="@+id/menu1_oneImage"
08. android:layout_width="106px"
09. android:layout_height="wrap_content"
10. android:layout_alignParentLeft="true"
11. android:layout_alignParentTop="true"
12. android:background="@drawable/nav_background_1"
13. />
14. <!-- 菜單one -->
15. <TextVIEw
16. android:id="@+id/menu1_oneText"
17. android:layout_width="wrap_content"
18. android:layout_height="wrap_content"
19. android:layout_alignLeft="@id/menu1_oneImage"
20. android:layout_alignTop="@id/menu1_oneImage"
21. android:layout_marginLeft="26px"
22. android:layout_marginTop="8px"
23. android:textColor="@color/black"
24. android:text="菜單1"
25. />
26. <!-- 菜單two -->
27. <ImageVIEw
28. android:id="@+id/menu1_twoImage"
29. android:layout_width="106px"
30. android:layout_height="wrap_content"
31. android:layout_toRightOf="@id/menu1_oneImage"
32. android:layout_alignTop="@id/menu1_oneImage"
33. android:background="@drawable/nav_background_2"
34. />
35. <!-- 菜單two 文字 -->
36. <TextVIEw
37. android:id="@+id/menu1_twoText"
38. android:layout_width="wrap_content"
39. android:layout_height="wrap_content"
40. android:layout_alignLeft="@id/menu1_twoImage"
41. android:layout_alignTop="@id/menu1_twoImage"
42. android:layout_marginLeft="26px"
43. android:layout_marginTop="8px"
44. android:textColor="@color/white"
45. android:text="菜單2"
46. />
47. <!-- 分隔線 -->
48. <ImageVIEw
49. android:id="@+id/menu1_lineImage"
50. android:layout_width="wrap_content"
51. android:layout_height="wrap_content"
52. android:layout_toRightOf="@id/menu1_twoImage"
53. android:layout_alignTop="@id/menu1_twoImage"
54. android:background="@drawable/nav_background_3"
55. />
56. <!-- 菜單three-->
57. <ImageVIEw
58. android:id="@+id/menu1_threeImage"
59. android:layout_width="106px"
60. android:layout_height="wrap_content"
61. android:layout_toRightOf="@id/menu1_lineImage"
62. android:layout_alignTop="@id/menu1_lineImage"
63. android:background="@drawable/nav_background_2"
64. />
65. <!-- 菜單three文字 -->
66. <TextVIEw
67. android:id="@+id/menu1_threeText"
68. android:layout_width="wrap_content"
69. android:layout_height="wrap_content"
70. android:layout_alignLeft="@id/menu1_threeImage"
71. android:layout_alignTop="@id/menu1_threeImage"
72. android:layout_marginLeft="26px"
73. android:layout_marginTop="8px"
74. android:textColor="@color/white"
75. android:text="菜單3"
76. />
77. <!-- 下邊框 -->
78. <ImageVIEw
79. android:id="@+id/menu1_bottomLine"
80. android:layout_width="fill_parent"
81. android:layout_height="wrap_content"
82. android:layout_below="@id/menu1_oneImage"
83. android:layout_alignLeft="@id/menu1_oneImage"
84. android:background="@drawable/nav_background_4"
85. />
86. <ScrollVIEw
87. android:layout_width="fill_parent"
88. android:layout_height="fill_parent"
89. android:layout_below="@id/menu1_bottomLine"
90. android:layout_alignParentLeft="true"
91. android:fadingEdge="vertical"
92. android:background="@drawable/back_white">
93. <RelativeLayout
94. android:layout_width="fill_parent"
95. android:layout_height="wrap_content">
96.
97. <TextVIEw
98. android:id="@+id/menu1_contentText"
99. android:layout_width="wrap_content"
100. android:layout_height="wrap_content"
101. android:layout_marginTop="10px"
102. android:textColor="@color/black"
103. android:text="這是文字內容...."
104. />
105. </RelativeLayout>
106. </ScrollVIEw>
107.</RelativeLayout>
<?XML version="1.0" encoding="UTF-8"?>
<RelativeLayout XMLns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- 菜單one -->
<ImageVIEw
android:id="@+id/menu1_oneImage"
android:layout_width="106px"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/nav_background_1"
/>
<!-- 菜單one -->
<TextVIEw
android:id="@+id/menu1_oneText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/menu1_oneImage"
android:layout_alignTop="@id/menu1_oneImage"
android:layout_marginLeft="26px"
android:layout_marginTop="8px"
android:textColor="@color/black"
android:text="菜單1"
/>
<!-- 菜單two -->
<ImageVIEw
android:id="@+id/menu1_twoImage"
android:layout_width="106px"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/menu1_oneImage"
android:layout_alignTop="@id/menu1_oneImage"
android:background="@drawable/nav_background_2"
/>
<!-- 菜單two 文字 -->
<TextVIEw
android:id="@+id/menu1_twoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/menu1_twoImage"
android:layout_alignTop="@id/menu1_twoImage"
android:layout_marginLeft="26px"
android:layout_marginTop="8px"
android:textColor="@color/white"
android:text="菜單2"
/>
<!-- 分隔線 -->
<ImageVIEw
android:id="@+id/menu1_lineImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/menu1_twoImage"
android:layout_alignTop="@id/menu1_twoImage"
android:background="@drawable/nav_background_3"
/>
<!-- 菜單three-->
<ImageVIEw
android:id="@+id/menu1_threeImage"
android:layout_width="106px"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/menu1_lineImage"
android:layout_alignTop="@id/menu1_lineImage"
android:background="@drawable/nav_background_2"
/>
<!-- 菜單three文字 -->
<TextVIEw
android:id="@+id/menu1_threeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/menu1_threeImage"
android:layout_alignTop="@id/menu1_threeImage"
android:layout_marginLeft="26px"
android:layout_marginTop="8px"
android:textColor="@color/white"
android:text="菜單3"
/>
<!-- 下邊框 -->
<ImageVIEw
android:id="@+id/menu1_bottomLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/menu1_oneImage"
android:layout_alignLeft="@id/menu1_oneImage"
android:background="@drawable/nav_background_4"
/>
<ScrollVIEw
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/menu1_bottomLine"
android:layout_alignParentLeft="true"
android:fadingEdge="vertical"
android:background="@drawable/back_white">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextVIEw
android:id="@+id/menu1_contentText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10px"
android:textColor="@color/black"
android:text="這是文字內容...."
/>
</RelativeLayout>
</ScrollVIEw>
</RelativeLayout>
menu2的布局文件-menu2.XML:
vIEw plaincopy to clipboardprint?
01.<?XML version="1.0" encoding="UTF-8"?>
02.<RelativeLayout XMLns:android="http://schemas.android.com/apk/res/android"
03. android:layout_width="fill_parent"
04. android:layout_height="wrap_content">
05. <!-- 菜單one -->
06. <ImageVIEw
07. android:id="@+id/menu2_oneImage"
08. android:layout_width="106px"
09. android:layout_height="wrap_content"
10. android:layout_alignParentLeft="true"
11. android:layout_alignParentTop="true"
12. android:background="@drawable/nav_background_2"
13. />
14. <!-- 菜單one -->
15. <TextVIEw
16. android:id="@+id/menu2_oneText"
17. android:layout_width="wrap_content"
18. android:layout_height="wrap_content"
19. android:layout_alignLeft="@id/menu2_oneImage"
20. android:layout_alignTop="@id/menu2_oneImage"
21. android:layout_marginLeft="26px"
22. android:layout_marginTop="8px"
23. android:textColor="@color/white"
24. android:text="菜單1"
25. />
26. <!-- 菜單two -->
27. <ImageVIEw
28. android:id="@+id/menu2_twoImage"
29. android:layout_width="106px"
30. android:layout_height="wrap_content"
31. android:layout_toRightOf="@id/menu2_oneImage"
32. android:layout_alignTop="@id/menu2_oneImage"
33. android:background="@drawable/nav_background_1"
34. />
35. <!-- 菜單two 文字 -->
36. <TextVIEw
37. android:id="@+id/menu2_twoText"
38. android:layout_width="wrap_content"
39. android:layout_height="wrap_content"
40. android:layout_alignLeft="@id/menu2_twoImage"
41. android:layout_alignTop="@id/menu2_twoImage"
42. android:layout_marginLeft="26px"
43. android:layout_marginTop="8px"
44. android:textColor="@color/black"
45. android:text="菜單2"
46. />
47. <!-- 菜單three-->
48. <ImageVIEw
49. android:id="@+id/menu2_threeImage"
50. android:layout_width="106px"
51. android:layout_height="wrap_content"
52. android:layout_toRightOf="@id/menu2_twoImage"
53. android:layout_alignTop="@id/menu2_twoImage"
54. android:background="@drawable/nav_background_2"
55. />
56. <!-- 菜單three文字 -->
57. <TextVIEw
58. android:id="@+id/menu2_threeText"
59. android:layout_width="wrap_content"
60. android:layout_height="wrap_content"
61. android:layout_alignLeft="@id/menu2_threeImage"
62. android:layout_alignTop="@id/menu2_threeImage"
63. android:layout_marginLeft="26px"
64. android:layout_marginTop="8px"
65. android:textColor="@color/white"
66. android:text="菜單3"
67. />
68. <!-- 下邊框 -->
69. <ImageVIEw
70. android:id="@+id/menu2_bottomLine"
71. android:layout_width="fill_parent"
72. android:layout_height="wrap_content"
73. android:layout_below="@id/menu2_oneImage"
74. android:layout_alignLeft="@id/menu2_oneImage"
75. android:background="@drawable/nav_background_4"
76. />
77. <ScrollVIEw
78. android:layout_width="fill_parent"
79. android:layout_height="fill_parent"
80. android:layout_below="@id/menu2_bottomLine"
81. android:layout_alignParentLeft="true"
82. android:fadingEdge="vertical"
83. android:background="@drawable/back_white">
84. <RelativeLayout
85. android:layout_width="fill_parent"
86. android:layout_height="wrap_content">
87.
88. <TextVIEw
89. android:id="@+id/menu2_contentText"
90. android:layout_width="wrap_content"
91. android:layout_height="wrap_content"
92. android:layout_marginTop="10px"
93. android:textColor="@color/black"
94. android:text="這是文字內容...."
95. />
96. </RelativeLayout>
97. </ScrollVIEw>
98.</RelativeLayout>
<?XML version="1.0" encoding="UTF-8"?>
<RelativeLayout XMLns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- 菜單one -->
<ImageVIEw
android:id="@+id/menu2_oneImage"
android:layout_width="106px"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/nav_background_2"
/>
<!-- 菜單one -->
<TextVIEw
android:id="@+id/menu2_oneText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/menu2_oneImage"
android:layout_alignTop="@id/menu2_oneImage"
android:layout_marginLeft="26px"
android:layout_marginTop="8px"
android:textColor="@color/white"
android:text="菜單1"
/>
<!-- 菜單two -->
<ImageVIEw
android:id="@+id/menu2_twoImage"
android:layout_width="106px"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/menu2_oneImage"
android:layout_alignTop="@id/menu2_oneImage"
android:background="@drawable/nav_background_1"
/>
<!-- 菜單two 文字 -->
<TextVIEw
android:id="@+id/menu2_twoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/menu2_twoImage"
android:layout_alignTop="@id/menu2_twoImage"
android:layout_marginLeft="26px"
android:layout_marginTop="8px"
android:textColor="@color/black"
android:text="菜單2"
/>
<!-- 菜單three-->
<ImageVIEw
android:id="@+id/menu2_threeImage"
android:layout_width="106px"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/menu2_twoImage"
android:layout_alignTop="@id/menu2_twoImage"
android:background="@drawable/nav_background_2"
/>
<!-- 菜單three文字 -->
<TextVIEw
android:id="@+id/menu2_threeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/menu2_threeImage"
android:layout_alignTop="@id/menu2_threeImage"
android:layout_marginLeft="26px"
android:layout_marginTop="8px"
android:textColor="@color/white"
android:text="菜單3"
/>
<!-- 下邊框 -->
<ImageVIEw
android:id="@+id/menu2_bottomLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/menu2_oneImage"
android:layout_alignLeft="@id/menu2_oneImage"
android:background="@drawable/nav_background_4"
/>
<ScrollVIEw
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/menu2_bottomLine"
android:layout_alignParentLeft="true"
android:fadingEdge="vertical"
android:background="@drawable/back_white">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextVIEw
android:id="@+id/menu2_contentText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10px"
android:textColor="@color/black"
android:text="這是文字內容...."
/>
</RelativeLayout>
</ScrollVIEw>
</RelativeLayout>
menu3的布局文件-menu3.XML:
vIEw plaincopy to clipboardprint?
01.<?XML version="1.0" encoding="UTF-8"?>
02.<RelativeLayout XMLns:android="http://schemas.android.com/apk/res/android"
03. android:layout_width="fill_parent"
04. android:layout_height="wrap_content">
05. <!-- 菜單one -->
06. <ImageVIEw
07. android:id="@+id/menu3_oneImage"
08. android:layout_width="106px"
09. android:layout_height="wrap_content"
10. android:layout_alignParentLeft="true"
11. android:layout_alignParentTop="true"
12. android:background="@drawable/nav_background_2"
13. />
14. <!-- 菜單one -->
15. <TextVIEw
16. android:id="@+id/menu3_oneText"
17. android:layout_width="wrap_content"
18. android:layout_height="wrap_content"
19. android:layout_alignLeft="@id/menu3_oneImage"
20. android:layout_alignTop="@id/menu3_oneImage"
21. android:layout_marginLeft="26px"
22. android:layout_marginTop="8px"
23. android:textColor="@color/white"
24. android:text="菜單1"
25. />
26. <!-- 分隔線 -->
27. <ImageVIEw
28. android:id="@+id/menu3_lineImage"
29. android:layout_width="wrap_content"
30. android:layout_height="wrap_content"
31. android:layout_toRightOf="@id/menu3_oneImage"
32. android:layout_alignTop="@id/menu3_oneImage"
33. android:background="@drawable/nav_background_3"
34. />
35. <!-- 菜單two -->
36. <ImageVIEw
37. android:id="@+id/menu3_twoImage"
38. android:layout_width="106px"
39. android:layout_height="wrap_content"
40. android:layout_toRightOf="@id/menu3_lineImage"
41. android:layout_alignTop="@id/menu3_lineImage"
42. android:background="@drawable/nav_background_2"
43. />
44. <!-- 菜單two 文字 -->
45. <TextVIEw
46. android:id="@+id/menu3_twoText"
47. android:layout_width="wrap_content"
48. android:layout_height="wrap_content"
49. android:layout_alignLeft="@id/menu3_twoImage"
50. android:layout_alignTop="@id/menu3_twoImage"
51. android:layout_marginLeft="26px"
52. android:layout_marginTop="8px"
53. android:textColor="@color/white"
54. android:text="菜單2"
55. />
56. <!-- 菜單three-->
57. <ImageVIEw
58. android:id="@+id/menu3_threeImage"
59. android:layout_width="106px"
60. android:layout_height="wrap_content"
61. android:layout_toRightOf="@id/menu3_twoImage"
62. android:layout_alignTop="@id/menu3_twoImage"
63. android:background="@drawable/nav_background_1"
64. />
65. <!-- 菜單three文字 -->
66. <TextVIEw
67. android:id="@+id/menu3_threeText"
68. android:layout_width="wrap_content"
69. android:layout_height="wrap_content"
70. android:layout_alignLeft="@id/menu3_threeImage"
71. android:layout_alignTop="@id/menu3_threeImage"
72. android:layout_marginLeft="26px"
73. android:layout_marginTop="8px"
74. android:textColor="@color/black"
75. android:text="菜單3"
76. />
77. <!-- 下邊框 -->
78. <ImageVIEw
79. android:id="@+id/menu3_bottomLine"
80. android:layout_width="fill_parent"
81. android:layout_height="wrap_content"
82. android:layout_below="@id/menu3_oneImage"
83. android:layout_alignLeft="@id/menu3_oneImage"
84. android:background="@drawable/nav_background_4"
85. />
86. <ScrollVIEw
87. android:layout_width="fill_parent"
88. android:layout_height="fill_parent"
89. android:layout_below="@id/menu3_bottomLine"
90. android:layout_alignParentLeft="true"
91. android:fadingEdge="vertical"
92. android:background="@drawable/back_white">
93. <RelativeLayout
94. android:layout_width="fill_parent"
95. android:layout_height="wrap_content">
96.
97. <TextVIEw
98. android:id="@+id/menu3_contentText"
99. android:layout_width="wrap_content"
100. android:layout_height="wrap_content"
101. android:layout_marginTop="10px"
102. android:textColor="@color/black"
103. android:text="這是文字內容...."
104. />
105. </RelativeLayout>
106. </ScrollVIEw>
107.</RelativeLayout>
<?XML version="1.0" encoding="UTF-8"?>
<RelativeLayout XMLns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- 菜單one -->
<ImageVIEw
android:id="@+id/menu3_oneImage"
android:layout_width="106px"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/nav_background_2"
/>
<!-- 菜單one -->
<TextVIEw
android:id="@+id/menu3_oneText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/menu3_oneImage"
android:layout_alignTop="@id/menu3_oneImage"
android:layout_marginLeft="26px"
android:layout_marginTop="8px"
android:textColor="@color/white"
android:text="菜單1"
/>
<!-- 分隔線 -->
<ImageVIEw
android:id="@+id/menu3_lineImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/menu3_oneImage"
android:layout_alignTop="@id/menu3_oneImage"
android:background="@drawable/nav_background_3"
/>
<!-- 菜單two -->
<ImageVIEw
android:id="@+id/menu3_twoImage"
android:layout_width="106px"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/menu3_lineImage"
android:layout_alignTop="@id/menu3_lineImage"
android:background="@drawable/nav_background_2"
/>
<!-- 菜單two 文字 -->
<TextVIEw
android:id="@+id/menu3_twoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/menu3_twoImage"
android:layout_alignTop="@id/menu3_twoImage"
android:layout_marginLeft="26px"
android:layout_marginTop="8px"
android:textColor="@color/white"
android:text="菜單2"
/>
<!-- 菜單three-->
<ImageVIEw
android:id="@+id/menu3_threeImage"
android:layout_width="106px"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/menu3_twoImage"
android:layout_alignTop="@id/menu3_twoImage"
android:background="@drawable/nav_background_1"
/>
<!-- 菜單three文字 -->
<TextVIEw
android:id="@+id/menu3_threeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/menu3_threeImage"
android:layout_alignTop="@id/menu3_threeImage"
android:layout_marginLeft="26px"
android:layout_marginTop="8px"
android:textColor="@color/black"
android:text="菜單3"
/>
<!-- 下邊框 -->
<ImageVIEw
android:id="@+id/menu3_bottomLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/menu3_oneImage"
android:layout_alignLeft="@id/menu3_oneImage"
android:background="@drawable/nav_background_4"
/>
<ScrollVIEw
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/menu3_bottomLine"
android:layout_alignParentLeft="true"
android:fadingEdge="vertical"
android:background="@drawable/back_white">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextVIEw
android:id="@+id/menu3_contentText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10px"
android:textColor="@color/black"
android:text="這是文字內容...."
/>
</RelativeLayout>
</ScrollVIEw>
</RelativeLayout>
menu1 對應的Activity :
vIEw plaincopy to clipboardprint?
01.import android.app.Activity;
02.import android.content.Intent;
03.import android.os.Bundle;
04.import android.view.VIEw;
05.import android.view.VIEw.OnClickListener;
06.import android.widget.ImageVIEw;
07.import android.widget.TextVIEw;
08.
09.public class MainActivity extends Activity {
10. private TextVIEw twoText;
11. private ImageVIEw twoImage;
12. private TextVIEw threeText;
13. private ImageVIEw threeImage;
14. private Intent intent;
15. @Override
16. public void onCreate(Bundle savedInstanceState) {
17. super.onCreate(savedInstanceState);
18. setContentVIEw(R.layout.main);
19. intent=new Intent();
20.
21. twoText=(TextView)findVIEwById(R.id.menu1_twoText);
22. twoImage=(ImageView)findVIEwById(R.id.menu1_twoImage);
23. threeText=(TextView)findVIEwById(R.id.menu1_threeText);
24. threeImage=(ImageView)findVIEwById(R.id.menu1_threeImage);
25.
26. twoText.setOnClickListener(new TwoOnClickListener());
27. twoImage.setOnClickListener(new TwoOnClickListener());
28. threeText.setOnClickListener(new ThreeOnClickListener());
29. threeImage.setOnClickListener(new ThreeOnClickListener());
30. }
31. class TwoOnClickListener implements OnClickListener{
32. @Override
33. public void onClick(VIEw v) {
34. intent.setClass(MainActivity.this,Menu2Activity.class);
35. startActivity(intent);
36. }
37. }
38. class ThreeOnClickListener implements OnClickListener{
39.
40. @Override
41. public void onClick(VIEw v) {
42. intent.setClass(MainActivity.this,Menu3Activity.class);
43. startActivity(intent);
44. }
45.
46. }
47.}
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.VIEw;
import android.view.VIEw.OnClickListener;
import android.widget.ImageVIEw;
import android.widget.TextVIEw;
public class MainActivity extends Activity {
private TextVIEw twoText;
private ImageVIEw twoImage;
private TextVIEw threeText;
private ImageVIEw threeImage;
private Intent intent;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentVIEw(R.layout.main);
intent=new Intent();
twoText=(TextView)findVIEwById(R.id.menu1_twoText);
twoImage=(ImageView)findVIEwById(R.id.menu1_twoImage);
threeText=(TextView)findVIEwById(R.id.menu1_threeText);
threeImage=(ImageView)findVIEwById(R.id.menu1_threeImage);
twoText.setOnClickListener(new TwoOnClickListener());
twoImage.setOnClickListener(new TwoOnClickListener());
threeText.setOnClickListener(new ThreeOnClickListener());
threeImage.setOnClickListener(new ThreeOnClickListener());
}
class TwoOnClickListener implements OnClickListener{
@Override
public void onClick(VIEw v) {
intent.setClass(MainActivity.this,Menu2Activity.class);
startActivity(intent);
}
}
class ThreeOnClickListener implements OnClickListener{
@Override
public void onClick(VIEw v) {
intent.setClass(MainActivity.this,Menu3Activity.class);
startActivity(intent);
}
}
}
menu2 對應的Activity:
vIEw plaincopy to clipboardprint?
01.import android.app.Activity;
02.import android.content.Intent;
03.import android.os.Bundle;
04.import android.view.VIEw;
05.import android.view.VIEw.OnClickListener;
06.import android.widget.ImageVIEw;
07.import android.widget.TextVIEw;
08.
09.public class Menu2Activity extends Activity {
10. private TextVIEw oneText;
11. private ImageVIEw oneImage;
12. private TextVIEw threeText;
13. private ImageVIEw threeImage;
14. private Intent intent;
15. @Override
16. public void onCreate(Bundle savedInstanceState) {
17. super.onCreate(savedInstanceState);
18. setContentVIEw(R.layout.menu2);
19. intent=new Intent();
20. oneText=(TextView)findVIEwById(R.id.menu2_oneText);
21. oneImage=(ImageView)findVIEwById(R.id.menu2_oneImage);
22. threeText=(TextView)findVIEwById(R.id.menu2_threeText);
23. threeImage=(ImageView)findVIEwById(R.id.menu2_threeImage);
24.
25. oneText.setOnClickListener(new OneOnClickListener());
26. oneImage.setOnClickListener(new OneOnClickListener());
27. threeText.setOnClickListener(new ThreeOnClickListener());
28. threeImage.setOnClickListener(new ThreeOnClickListener());
29. }
30. class OneOnClickListener implements OnClickListener {
31. @Override
32. public void onClick(VIEw v) {
33. intent.setClass(Menu2Activity.this,MainActivity.class);
34. startActivity(intent);
35. }
36. }
37. class ThreeOnClickListener implements OnClickListener{
38.
39. @Override
40. public void onClick(VIEw v) {
41. intent.setClass(Menu2Activity.this,Menu3Activity.class);
42. startActivity(intent);
43. }
44.
45. }
46.}
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.VIEw;
import android.view.VIEw.OnClickListener;
import android.widget.ImageVIEw;
import android.widget.TextVIEw;
public class Menu2Activity extends Activity {
private TextVIEw oneText;
private ImageVIEw oneImage;
private TextVIEw threeText;
private ImageVIEw threeImage;
private Intent intent;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentVIEw(R.layout.menu2);
intent=new Intent();
oneText=(TextView)findVIEwById(R.id.menu2_oneText);
oneImage=(ImageView)findVIEwById(R.id.menu2_oneImage);
threeText=(TextView)findVIEwById(R.id.menu2_threeText);
threeImage=(ImageView)findVIEwById(R.id.menu2_threeImage);
oneText.setOnClickListener(new OneOnClickListener());
oneImage.setOnClickListener(new OneOnClickListener());
threeText.setOnClickListener(new ThreeOnClickListener());
threeImage.setOnClickListener(new ThreeOnClickListener());
}
class OneOnClickListener implements OnClickListener {
@Override
public void onClick(VIEw v) {
intent.setClass(Menu2Activity.this,MainActivity.class);
startActivity(intent);
}
}
class ThreeOnClickListener implements OnClickListener{
@Override
public void onClick(VIEw v) {
intent.setClass(Menu2Activity.this,Menu3Activity.class);
startActivity(intent);
}
}
}
menu3 對應的Activity:
vIEw plaincopy to clipboardprint?
01.import android.app.Activity;
02.import android.content.Intent;
03.import android.os.Bundle;
04.import android.view.VIEw;
05.import android.view.VIEw.OnClickListener;
06.import android.widget.ImageVIEw;
07.import android.widget.TextVIEw;
08.
09.public class Menu3Activity extends Activity {
10. private TextVIEw oneText;
11. private ImageVIEw oneImage;
12. private TextVIEw twoText;
13. private ImageVIEw twoImage;
14. private Intent intent;
15. @Override
16. public void onCreate(Bundle savedInstanceState) {
17. super.onCreate(savedInstanceState);
18. setContentVIEw(R.layout.menu3);
19. intent=new Intent();
20. oneText=(TextView)findVIEwById(R.id.menu3_oneText);
21. oneImage=(ImageView)findVIEwById(R.id.menu3_oneImage);
22. twoText=(TextView)findVIEwById(R.id.menu3_twoText);
23. twoImage=(ImageView)findVIEwById(R.id.menu3_twoImage);
24.
25. oneText.setOnClickListener(new OneOnClickListener());
26. oneImage.setOnClickListener(new OneOnClickListener());
27. twoText.setOnClickListener(new TwoOnClickListener());
28. twoImage.setOnClickListener(new TwoOnClickListener());
29. }
30. class OneOnClickListener implements OnClickListener {
31. @Override
32. public void onClick(VIEw v) {
33. intent.setClass(Menu3Activity.this,MainActivity.class);
34. startActivity(intent);
35. }
36. }
37. class TwoOnClickListener implements OnClickListener{
38. @Override
39. public void onClick(VIEw v) {
40. intent.setClass(Menu3Activity.this,Menu2Activity.class);
41. startActivity(intent);
42. }
43. }
44.}
外特性空間的Activity 我們先來看看,Android應用開發人員接觸的外特性空間中的Activity,對於AMS (activ
HTC Hero作為一款硬件配置強悍的智能手機,對不同版本的android系統兼容性非常好,曾有用戶將HTC新機Espresso內的2.1版android系統和最新的S
l 使用Intent物件雖然透過Intent並非最快速,但卻是最有彈性的。無論是同一進程或是跨進程的溝通都可以使用它。例如:/* ===== EX-02 ======
摘自:http://www.eoeandroid.com/thread-15411-1-1.HtmlFailed to push XXXXX.txt on emulat