(android地图开发) 高德地图手势切换

逃离我推掉我的手 2024-04-17 05:45 168阅读 0赞

效果截图:

CenterCenter 1Center 2

相关布局文件:

(手势滑动第一个界面)

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="fill_parent"
  3. android:layout_height="fill_parent"
  4. android:orientation="vertical"
  5. android:background="#ffffff"
  6. >
  7. <LinearLayout
  8. android:layout_width="fill_parent"
  9. android:layout_height="42dp"
  10. android:background="#ffffff"
  11. android:orientation="horizontal" >
  12. <ImageView
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:layout_margin="6dp"
  16. android:background="@drawable/ml_card_bg"
  17. android:src="@drawable/back_btn" >
  18. </ImageView>
  19. <LinearLayout
  20. android:layout_width="210dp"
  21. android:layout_height="wrap_content"
  22. android:layout_marginBottom="6dp"
  23. android:layout_marginTop="6dp"
  24. android:background="@drawable/sapi_input"
  25. android:orientation="horizontal" >
  26. <ImageView
  27. android:layout_width="wrap_content"
  28. android:layout_height="wrap_content"
  29. android:layout_marginTop="5dp"
  30. android:background="@drawable/change" />
  31. <TextView
  32. android:layout_width="wrap_content"
  33. android:layout_height="wrap_content"
  34. android:layout_gravity="center"
  35. android:layout_margin="2dp"
  36. android:hint="地点、地铁、公交..."
  37. android:textColor="@color/grey"
  38. android:textSize="16dp" >
  39. </TextView>
  40. </LinearLayout>
  41. <Button
  42. android:layout_width="wrap_content"
  43. android:layout_height="wrap_content"
  44. android:layout_marginBottom="6dp"
  45. android:layout_marginTop="6dp"
  46. android:background="@drawable/header_voice_normal" >
  47. </Button>
  48. </LinearLayout>
  49. <LinearLayout
  50. android:layout_width="fill_parent"
  51. android:layout_height="16dp"
  52. android:background="#ffffff"
  53. android:gravity="center"
  54. android:orientation="horizontal" >
  55. <ImageView
  56. android:layout_width="wrap_content"
  57. android:layout_height="wrap_content"
  58. android:src="@drawable/icon_scrollview_cur" >
  59. </ImageView>
  60. <View
  61. android:layout_width="16dp"
  62. android:layout_height="wrap_content" >
  63. </View>
  64. <ImageView
  65. android:layout_width="wrap_content"
  66. android:layout_height="wrap_content"
  67. android:src="@drawable/icon_scrollview_notcur" >
  68. </ImageView>
  69. <View
  70. android:layout_width="16dp"
  71. android:layout_height="wrap_content" >
  72. </View>
  73. <ImageView
  74. android:layout_width="wrap_content"
  75. android:layout_height="wrap_content"
  76. android:src="@drawable/icon_scrollview_notcur" >
  77. </ImageView>
  78. </LinearLayout>
  79. <LinearLayout
  80. android:layout_width="fill_parent"
  81. android:layout_height="fill_parent"
  82. android:layout_marginTop="6dp"
  83. android:orientation="vertical" >
  84. <ListView
  85. android:id="@+id/list_search_me"
  86. android:layout_width="fill_parent"
  87. android:layout_height="wrap_content" >
  88. </ListView>
  89. </LinearLayout>
  90. </LinearLayout>

(手势滑动第二个界面)

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="fill_parent"
  3. android:layout_height="fill_parent"
  4. android:orientation="vertical"
  5. android:background="#ffffff"
  6. >
  7. <LinearLayout
  8. android:layout_width="fill_parent"
  9. android:layout_height="42dp"
  10. android:background="#ffffff"
  11. android:orientation="horizontal" >
  12. <ImageView
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:layout_margin="6dp"
  16. android:background="@drawable/ml_card_bg"
  17. android:src="@drawable/back_btn" >
  18. </ImageView>
  19. <LinearLayout
  20. android:layout_width="210dp"
  21. android:layout_height="wrap_content"
  22. android:layout_marginBottom="6dp"
  23. android:layout_marginTop="6dp"
  24. android:background="@drawable/sapi_input"
  25. android:orientation="horizontal" >
  26. <ImageView
  27. android:layout_width="wrap_content"
  28. android:layout_height="wrap_content"
  29. android:layout_marginTop="5dp"
  30. android:background="@drawable/change" />
  31. <TextView
  32. android:layout_width="wrap_content"
  33. android:layout_height="wrap_content"
  34. android:layout_gravity="center"
  35. android:layout_margin="2dp"
  36. android:hint="地点、地铁、公交..."
  37. android:textColor="@color/grey"
  38. android:textSize="16dp" >
  39. </TextView>
  40. </LinearLayout>
  41. <Button
  42. android:layout_width="wrap_content"
  43. android:layout_height="wrap_content"
  44. android:layout_marginBottom="6dp"
  45. android:layout_marginTop="6dp"
  46. android:background="@drawable/header_voice_normal" >
  47. </Button>
  48. </LinearLayout>
  49. <LinearLayout
  50. android:layout_width="fill_parent"
  51. android:layout_height="16dp"
  52. android:background="#ffffff"
  53. android:gravity="center"
  54. android:orientation="horizontal" >
  55. <ImageView
  56. android:layout_width="wrap_content"
  57. android:layout_height="wrap_content"
  58. android:src="@drawable/icon_scrollview_notcur" >
  59. </ImageView>
  60. <View
  61. android:layout_width="16dp"
  62. android:layout_height="wrap_content" >
  63. </View>
  64. <ImageView
  65. android:layout_width="wrap_content"
  66. android:layout_height="wrap_content"
  67. android:src="@drawable/icon_scrollview_cur" >
  68. </ImageView>
  69. <View
  70. android:layout_width="16dp"
  71. android:layout_height="wrap_content" >
  72. </View>
  73. <ImageView
  74. android:layout_width="wrap_content"
  75. android:layout_height="wrap_content"
  76. android:src="@drawable/icon_scrollview_notcur" >
  77. </ImageView>
  78. </LinearLayout>
  79. <LinearLayout
  80. android:layout_width="fill_parent"
  81. android:layout_height="fill_parent"
  82. android:layout_marginTop="6dp"
  83. android:orientation="vertical"
  84. >
  85. <GridView
  86. android:id="@+id/grid_search_launcher"
  87. android:layout_width="fill_parent"
  88. android:layout_height="fill_parent"
  89. android:horizontalSpacing="8dp"
  90. android:numColumns="5"
  91. android:verticalSpacing="6dp" >
  92. </GridView>
  93. </LinearLayout>
  94. </LinearLayout>

(手势滑动第三个界面)

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="fill_parent"
  3. android:layout_height="fill_parent"
  4. android:orientation="vertical" >
  5. <LinearLayout
  6. android:layout_width="fill_parent"
  7. android:layout_height="42dp"
  8. android:background="#ffffff"
  9. android:orientation="horizontal" >
  10. <ImageView
  11. android:layout_width="wrap_content"
  12. android:layout_height="wrap_content"
  13. android:layout_margin="6dp"
  14. android:background="@drawable/ml_card_bg"
  15. android:src="@drawable/back_btn" >
  16. </ImageView>
  17. <LinearLayout
  18. android:layout_width="210dp"
  19. android:layout_height="wrap_content"
  20. android:layout_marginBottom="6dp"
  21. android:layout_marginTop="6dp"
  22. android:background="@drawable/sapi_input"
  23. android:orientation="horizontal" >
  24. <ImageView
  25. android:layout_width="wrap_content"
  26. android:layout_height="wrap_content"
  27. android:layout_marginTop="5dp"
  28. android:background="@drawable/change" />
  29. <TextView
  30. android:layout_width="wrap_content"
  31. android:layout_height="wrap_content"
  32. android:layout_gravity="center"
  33. android:layout_margin="2dp"
  34. android:hint="地点、地铁、公交..."
  35. android:textColor="@color/grey"
  36. android:textSize="16dp" >
  37. </TextView>
  38. </LinearLayout>
  39. <Button
  40. android:layout_width="wrap_content"
  41. android:layout_height="wrap_content"
  42. android:layout_marginBottom="6dp"
  43. android:layout_marginTop="6dp"
  44. android:background="@drawable/header_voice_normal" >
  45. </Button>
  46. </LinearLayout>
  47. <LinearLayout
  48. android:layout_width="fill_parent"
  49. android:layout_height="16dp"
  50. android:background="#ffffff"
  51. android:gravity="center"
  52. android:orientation="horizontal" >
  53. <ImageView
  54. android:layout_width="wrap_content"
  55. android:layout_height="wrap_content"
  56. android:src="@drawable/icon_scrollview_notcur" >
  57. </ImageView>
  58. <View
  59. android:layout_width="16dp"
  60. android:layout_height="wrap_content" >
  61. </View>
  62. <ImageView
  63. android:layout_width="wrap_content"
  64. android:layout_height="wrap_content"
  65. android:src="@drawable/icon_scrollview_notcur" >
  66. </ImageView>
  67. <View
  68. android:layout_width="16dp"
  69. android:layout_height="wrap_content" >
  70. </View>
  71. <ImageView
  72. android:layout_width="wrap_content"
  73. android:layout_height="wrap_content"
  74. android:src="@drawable/icon_scrollview_cur" >
  75. </ImageView>
  76. </LinearLayout>
  77. <LinearLayout
  78. android:layout_width="fill_parent"
  79. android:layout_height="fill_parent"
  80. android:layout_marginTop="6dp"
  81. android:orientation="vertical" >
  82. <GridView
  83. android:id="@+id/grid_search_life"
  84. android:layout_width="fill_parent"
  85. android:layout_height="fill_parent"
  86. android:horizontalSpacing="8dp"
  87. android:numColumns="5"
  88. android:verticalSpacing="6dp" >
  89. </GridView>
  90. </LinearLayout>
  91. </LinearLayout>

源代码:

(滑动第一个页面)

  1. package com.rf.mapabc;
  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.view.GestureDetector;
  6. import android.view.MotionEvent;
  7. import android.view.View;
  8. import android.view.View.OnTouchListener;
  9. import android.view.Window;
  10. import android.view.WindowManager;
  11. import android.view.GestureDetector.OnGestureListener;
  12. public class SearchActivity extends Activity implements OnGestureListener {
  13. // 手势检测器
  14. GestureDetector detector;
  15. @Override
  16. public void onCreate(Bundle savedInstanceState) {
  17. // TODO Auto-generated method stub
  18. super.onCreate(savedInstanceState);
  19. // 全屏
  20. requestWindowFeature(Window.FEATURE_NO_TITLE);
  21. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  22. WindowManager.LayoutParams.FLAG_FULLSCREEN);
  23. setContentView(R.layout.search);
  24. detector = new GestureDetector(this);
  25. //ListView 数据实例化方法在此编写
  26. }
  27. //相关的覆写方法
  28. @Override
  29. public boolean onDown(MotionEvent e) {
  30. // TODO Auto-generated method stub
  31. return false;
  32. }
  33. @Override
  34. public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
  35. float velocityY) {
  36. // TODO Auto-generated method stub
  37. if (e1.getX() - e2.getX() > 50) {
  38. // 相关页面的滑动
  39. Intent intent = new Intent(SearchActivity.this, Search_middleActivity.class);
  40. startActivity(intent);
  41. return true;
  42. }
  43. return true;
  44. }
  45. @Override
  46. public void onLongPress(MotionEvent e) {
  47. // TODO Auto-generated method stub
  48. }
  49. @Override
  50. public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
  51. float distanceY) {
  52. // TODO Auto-generated method stub
  53. return false;
  54. }
  55. @Override
  56. public void onShowPress(MotionEvent e) {
  57. // TODO Auto-generated method stub
  58. }
  59. @Override
  60. public boolean onSingleTapUp(MotionEvent e) {
  61. // TODO Auto-generated method stub
  62. return false;
  63. }
  64. //添加事件处理函数
  65. @Override
  66. public boolean onTouchEvent(MotionEvent event) {
  67. // TODO Auto-generated method stub
  68. return this.detector.onTouchEvent(event);
  69. }
  70. }

(滑动第二个页面)

  1. package com.rf.mapabc;
  2. import com.rf.adapter.ImageAdapter;
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.view.GestureDetector;
  7. import android.view.MotionEvent;
  8. import android.view.View;
  9. import android.view.View.OnTouchListener;
  10. import android.view.Window;
  11. import android.view.WindowManager;
  12. import android.view.GestureDetector.OnGestureListener;
  13. import android.widget.GridView;
  14. import android.widget.SlidingDrawer;
  15. public class Search_middleActivity extends Activity implements OnGestureListener {
  16. // 手势检测器
  17. GestureDetector detector;
  18. @Override
  19. public void onCreate(Bundle savedInstanceState) {
  20. // TODO Auto-generated method stub
  21. super.onCreate(savedInstanceState);
  22. //全屏代码
  23. requestWindowFeature(Window.FEATURE_NO_TITLE);
  24. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  25. WindowManager.LayoutParams.FLAG_FULLSCREEN);
  26. setContentView(R.layout.search_middle);
  27. // 手势监听实例化代码
  28. detector = new GestureDetector(this);
  29. //组件类
  30. final GridView gridview=(GridView) findViewById(R.id.grid_search_launcher);
  31. //相关资源组件
  32. int[] images=new int[]{
  33. R.drawable.pg1,
  34. R.drawable.pg2,
  35. R.drawable.pg3,
  36. R.drawable.pg4,
  37. R.drawable.pg5,
  38. R.drawable.pg6,
  39. R.drawable.pg7,
  40. R.drawable.pg8,
  41. R.drawable.pg9,
  42. R.drawable.pg10
  43. };
  44. String[] contents=new String[]{
  45. "团购","美食","酒店","公交站","银行","电影院","KTV","丽人","超市","景点"
  46. };
  47. //自定义适配器
  48. final ImageAdapter adapter=new ImageAdapter(this,images,contents);
  49. gridview.setAdapter(adapter);
  50. }
  51. //覆写相关方法
  52. @Override
  53. public boolean onDown(MotionEvent e) {
  54. // TODO Auto-generated method stub
  55. return false;
  56. }
  57. @Override
  58. public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
  59. float velocityY) {
  60. // TODO Auto-generated method stub
  61. // TODO Auto-generated method stub
  62. // e1 触摸的起始位置,e2 触摸的结束位置,velocityX X轴每一秒移动的像素速度(大概这个意思) velocityY 就是Y咯
  63. // 手势左,上为正 ——,右,下为负正
  64. if (e2.getX() - e1.getX() > 50) {
  65. // 为什么是50? 这个根据你的模拟器大小来定,看看模拟器宽度,e2.getX()-e1.getX()<屏幕宽度就OK
  66. // 要触发什么事件都在这里写就OK
  67. // 如果要跳转到另外一个activity//SecondActivity
  68. Intent intent = new Intent(Search_middleActivity.this, SearchActivity.class);
  69. startActivity(intent);
  70. return true;
  71. }
  72. if (Math.abs(e2.getX() - e1.getX()) > 50) {
  73. Intent intent = new Intent(Search_middleActivity.this, Search_endActivity.class);
  74. startActivity(intent);
  75. return true;
  76. }
  77. return false;
  78. }
  79. @Override
  80. public void onLongPress(MotionEvent e) {
  81. // TODO Auto-generated method stub
  82. }
  83. @Override
  84. public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
  85. float distanceY) {
  86. // TODO Auto-generated method stub
  87. return false;
  88. }
  89. @Override
  90. public void onShowPress(MotionEvent e) {
  91. // TODO Auto-generated method stub
  92. }
  93. @Override
  94. public boolean onSingleTapUp(MotionEvent e) {
  95. // TODO Auto-generated method stub
  96. return false;
  97. }
  98. //事件方法
  99. @Override
  100. public boolean onTouchEvent(MotionEvent event) {
  101. // TODO Auto-generated method stub
  102. return this.detector.onTouchEvent(event);
  103. }
  104. }

(滑动第三个界面)

  1. package com.rf.mapabc;
  2. import com.rf.adapter.ImageAdapter;
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.view.GestureDetector;
  7. import android.view.MotionEvent;
  8. import android.view.View;
  9. import android.view.View.OnTouchListener;
  10. import android.view.Window;
  11. import android.view.WindowManager;
  12. import android.view.GestureDetector.OnGestureListener;
  13. import android.widget.GridView;
  14. public class Search_endActivity extends Activity implements OnGestureListener{
  15. // 手势检测器
  16. GestureDetector detector;
  17. @Override
  18. public void onCreate(Bundle savedInstanceState) {
  19. // TODO Auto-generated method stub
  20. super.onCreate(savedInstanceState);
  21. //全屏代码
  22. requestWindowFeature(Window.FEATURE_NO_TITLE);
  23. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  24. WindowManager.LayoutParams.FLAG_FULLSCREEN);
  25. setContentView(R.layout.serach_end);
  26. // 手势监听实例化代码
  27. detector = new GestureDetector(this);
  28. //组件类
  29. final GridView gridview=(GridView) findViewById(R.id.grid_search_life);
  30. //相关资源组件
  31. int[] images=new int[]{
  32. R.drawable.pg1,
  33. R.drawable.pg2,
  34. R.drawable.pg3,
  35. R.drawable.pg4,
  36. R.drawable.pg5,
  37. R.drawable.pg6,
  38. R.drawable.pg7,
  39. R.drawable.pg8,
  40. R.drawable.pg9,
  41. R.drawable.pg10
  42. };
  43. String[] contents=new String[]{
  44. "团购","美食","酒店","公交站","银行","电影院","KTV","丽人","超市","景点"
  45. };
  46. //自定义适配器
  47. final ImageAdapter adapter=new ImageAdapter(this,images,contents);
  48. gridview.setAdapter(adapter);
  49. }
  50. //覆写相关方法
  51. @Override
  52. public boolean onDown(MotionEvent e) {
  53. // TODO Auto-generated method stub
  54. return false;
  55. }
  56. @Override
  57. public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
  58. float velocityY) {
  59. // TODO Auto-generated method stub
  60. if (e2.getX() - e1.getX() > 50) {
  61. // 为什么是50? 这个根据你的模拟器大小来定,看看模拟器宽度,e2.getX()-e1.getX()<屏幕宽度就OK
  62. // 要触发什么事件都在这里写就OK
  63. // 如果要跳转到另外一个activity//SecondActivity
  64. Intent intent = new Intent(Search_endActivity.this, Search_middleActivity.class);
  65. startActivity(intent);
  66. return true;
  67. }
  68. return true;
  69. }
  70. @Override
  71. public void onLongPress(MotionEvent e) {
  72. // TODO Auto-generated method stub
  73. }
  74. @Override
  75. public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
  76. float distanceY) {
  77. // TODO Auto-generated method stub
  78. return false;
  79. }
  80. @Override
  81. public void onShowPress(MotionEvent e) {
  82. // TODO Auto-generated method stub
  83. }
  84. @Override
  85. public boolean onSingleTapUp(MotionEvent e) {
  86. // TODO Auto-generated method stub
  87. return false;
  88. }
  89. //事件监听
  90. @Override
  91. public boolean onTouchEvent(MotionEvent event) {
  92. // TODO Auto-generated method stub
  93. return this.detector.onTouchEvent(event);
  94. }
  95. }

发表评论

表情:
评论列表 (有 0 条评论,168人围观)

还没有评论,来说两句吧...

相关阅读