編輯:中級開發
res\layout\main.XML
Java代碼
1.<?XML version="1.0" encoding="utf-8"?>
2.<LinearLayout XMLns:android="http://schemas.android.com/apk/res/android"
3. android:orIEntation="vertical"
4. android:layout_width="fill_parent"
5. android:layout_height="fill_parent"
6. android:background="#ffffff"
7. >
8.
9. <VIEwFlipper android:id="@+id/details"
10. android:layout_width="fill_parent"
11. android:layout_height="fill_parent">
12.
13. <LinearLayout
14. android:orIEntation="vertical"
15. android:layout_width="fill_parent"
16. android:layout_height="fill_parent"
17. android:background="#ffffff">
18.
19. <TextVIEw android:id="@+id/tv_country"
20. android:layout_width="fill_parent"
21. android:layout_height="wrap_content"
22. android:textColor="#000000"
23. android:textStyle="bold"
24. android:textSize="18px"
25. android:text="Country" >
26. </TextVIEw>
27. <Spinner android:text=""
28. android:id="@+id/spinner_country"
29. android:layout_width="200px"
30. android:layout_height="55px">
31. </Spinner>
32. <Button android:text="Next"
33. android:id="@+id/Button_next"
34. android:layout_width="250px"
35. android:textSize="18px"
36. android:layout_height="55px">
37. </Button>
38. </LinearLayout>
39.
40. <LinearLayout
41. android:orIEntation="vertical"
42. android:layout_width="fill_parent"
43. android:layout_height="fill_parent"
44. android:background="#ffffff">
45.
46. <TextVIEw android:id="@+id/tv_income"
47. android:layout_width="fill_parent"
48. android:layout_height="wrap_content"
49. android:textColor="#000000"
50. android:textStyle="bold"
51. android:textSize="18px"
52. android:text="Income" >
53. </TextVIEw>
54. <EditText android:text=""
55. android:id="@+id/et_income"
56. android:layout_width="200px"
57. android:layout_height="55px">
58. </EditText>
59. <Button android:text="Previous"
60. android:id="@+id/Button_previous"
61. android:layout_width="250px"
62. android:textSize="18px"
63. android:layout_height="55px">
64. </Button>
65. </LinearLayout>
66.
67. </VIEwFlipper>
68.
69.</LinearLayout>
<?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:background="#ffffff"
>
<VIEwFlipper android:id="@+id/details"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orIEntation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff">
<TextVIEw android:id="@+id/tv_country"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="18px"
android:text="Country" >
</TextVIEw>
<Spinner android:text=""
android:id="@+id/spinner_country"
android:layout_width="200px"
android:layout_height="55px">
</Spinner>
<Button android:text="Next"
android:id="@+id/Button_next"
android:layout_width="250px"
android:textSize="18px"
android:layout_height="55px">
</Button>
</LinearLayout>
<LinearLayout
android:orIEntation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff">
<TextVIEw android:id="@+id/tv_income"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="18px"
android:text="Income" >
</TextVIEw>
<EditText android:text=""
android:id="@+id/et_income"
android:layout_width="200px"
android:layout_height="55px">
</EditText>
<Button android:text="Previous"
android:id="@+id/Button_previous"
android:layout_width="250px"
android:textSize="18px"
android:layout_height="55px">
</Button>
</LinearLayout>
</VIEwFlipper>
</LinearLayout>這裡唯一需要注意的就是VIEwFlipper標簽內包含兩個LinearLayout標簽,每一個LinearLayout標簽代表一屏。
Java代碼
1.public class Activity1 extends Activity {
2. /** Called when the activity is first created. */
3. @Override
4. public void onCreate(Bundle savedInstanceState) {
5. super.onCreate(savedInstanceState);
6.
7. // Set main.XML as the layout for this Activity
8. setContentVIEw(R.layout.main);
9.
10. // Add a few countrIEs to the spinner
11. Spinner spinnerCountries = (Spinner) findVIEwById(R.id.spinner_country);
12. ArrayAdapter countryArrayAdapter = new ArrayAdapter(this,
13. android.R.layout.simple_spinner_dropdown_item,
14. new String[] { "Canada", "USA" });
15. spinnerCountrIEs.setAdapter(countryArrayAdapter);
16.
17. // Set the listener for Button_Next, a quick and dirty way to create a listener
18. Button buttonNext = (Button) findVIEwById(R.id.Button_next);
19. buttonNext.setOnClickListener(new VIEw.OnClickListener() {
20. public void onClick(View vIEw) {
21. // Get the VIEwFlipper from the layout
22. ViewFlipper vf = (ViewFlipper) findVIEwById(R.id.details);
23.
24. // Set an animation from res/anim: I pick push left in
25. vf.setAnimation(AnimationUtils.loadAnimation(vIEw.getContext(), R.anim.push_left_in));
26. vf.showNext();
27. }
28. });
29.
30. // Set the listener for Button_Previous, a quick and dirty way to create a listener
31. Button buttonPrevious = (Button) findVIEwById(R.id.Button_previous);
32. buttonPrevious.setOnClickListener(new VIEw.OnClickListener() {
33. public void onClick(View vIEw) {
34. // Get the VIEwFlipper from the layout
35. ViewFlipper vf = (ViewFlipper) findVIEwById(R.id.details);
36. // Set an animation from res/anim: I pick push left out
37. vf.setAnimation(AnimationUtils.loadAnimation(vIEw.getContext(), R.anim.push_left_out));
38. vf.showPrevious();
39. }
40.
41. });
42.
43. }
public class Activity1 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set main.XML as the layout for this Activity
setContentVIEw(R.layout.main);
// Add a few countrIEs to the spinner
Spinner spinnerCountries = (Spinner) findVIEwById(R.id.spinner_country);
ArrayAdapter countryArrayAdapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_dropdown_item,
new String[] { "Canada", "USA" });
spinnerCountrIEs.setAdapter(countryArrayAdapter);
// Set the listener for Button_Next, a quick and dirty way to create a listener
Button buttonNext = (Button) findVIEwById(R.id.Button_next);
buttonNext.setOnClickListener(new VIEw.OnClickListener() {
public void onClick(View vIEw) {
// Get the VIEwFlipper from the layout
ViewFlipper vf = (ViewFlipper) findVIEwById(R.id.details);
// Set an animation from res/anim: I pick push left in
vf.setAnimation(AnimationUtils.loadAnimation(vIEw.getContext(), R.anim.push_left_in));
vf.showNext();
}
});
// Set the listener for Button_Previous, a quick and dirty way to create a listener
Button buttonPrevious = (Button) findVIEwById(R.id.Button_previous);
buttonPrevious.setOnClickListener(new VIEw.OnClickListener() {
public void onClick(View vIEw) {
// Get the VIEwFlipper from the layout
ViewFlipper vf = (ViewFlipper) findVIEwById(R.id.details);
// Set an animation from res/anim: I pick push left out
vf.setAnimation(AnimationUtils.loadAnimation(vIEw.getContext(), R.anim.push_left_out));
vf.showPrevious();
}
});
}
slide_right 代替push_left_out效果更好 一些,這些代碼都是api裡面自帶的。
上面的方法實現的是通過按鈕進行屏幕轉化,可是我想通過手指實現如何呢?
Java代碼
1.<?XML version="1.0" encoding="utf-8"?>
2.<LinearLayout XMLns:android="http://schemas.android.com/apk/res/android"
3. android:orIEntation="vertical"
4. android:layout_width="fill_parent"
5. android:layout_height="fill_parent"
6. android:background="#ffffff"
7. android:id="@+id/layout_main"
8. >
9.
10. <VIEwFlipper android:id="@+id/details"
11. android:layout_width="fill_parent"
12. android:layout_height="fill_parent">
13.
14. <LinearLayout
15. android:orIEntation="vertical"
16. android:layout_width="fill_parent"
17. android:layout_height="fill_parent"
18. android:background="#ffffff">
19.
20. <TextVIEw android:id="@+id/tv_country"
21. android:layout_width="fill_parent"
22. android:layout_height="wrap_content"
23. android:textColor="#000000"
24. android:textStyle="bold"
25. android:textSize="18px"
26. android:text="Country" >
27. </TextVIEw>
28. <Spinner android:text=""
29. android:id="@+id/spinner_country"
30. android:layout_width="200px"
31. android:layout_height="55px">
32. </Spinner>
33. </LinearLayout>
34.
35. <LinearLayout
36. android:orIEntation="vertical"
37. android:layout_width="fill_parent"
38. android:layout_height="fill_parent"
39. android:background="#ffffff">
40.
41. <TextVIEw android:id="@+id/tv_income"
42. android:layout_width="fill_parent"
43. android:layout_height="wrap_content"
44. android:textColor="#000000"
45. android:textStyle="bold"
46. android:textSize="18px"
47. android:text="Income" >
48. </TextVIEw>
49. <EditText android:text=""
50. android:id="@+id/et_income"
51. android:layout_width="200px"
52. android:layout_height="55px">
53. </EditText>
54. </LinearLayout>
55.
56. </VIEwFlipper>
57.
58.</LinearLayout>
收集用戶數據您已經創建了 Activity 主屏幕布局,現在可以創建用戶界面表單來收集數據了。在本例中,您將創建一個 Robotics Club R
Android ANR這個錯誤大家並不陌生,但是從Android 2.2開始出錯的ANR信息會自動上傳給Google進行系統分析改進,當然了你的應用ANR錯誤其實保存在
簡介: 學習了解 IBM® Rational® Rhapsody® V7.5.2 版本中的新特性與改進之處,幫助系統管理員和實時、嵌入
簡介: HTML 5 針對移動 Web 應用程序引入了大量新特性,其中包括一些可視化特性,它們通常會帶來強烈的視覺沖擊。Canvas 是最引人注目的新 UI