(android地图开发) 高德地图自定义对话框

柔情只为你懂 2023-10-19 08:10 274阅读 0赞

截图效果:

Center

布局文件:

  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="horizontal"
  5. android:background="#ffffff"
  6. >
  7. <!--卫星地图 -->
  8. <ImageButton
  9. android:id="@+id/satellite"
  10. android:layout_weight="1"
  11. android:layout_width="wrap_content"
  12. android:layout_height="wrap_content"
  13. android:src="@drawable/main_map_mode_satellite_normal"
  14. >
  15. </ImageButton>
  16. <!--平面地图 -->
  17. <ImageButton
  18. android:id="@+id/plain"
  19. android:layout_width="wrap_content"
  20. android:layout_height="wrap_content"
  21. android:layout_weight="1"
  22. android:src="@drawable/main_map_mode_plain_normal" />
  23. <!--3d地图 -->
  24. <ImageButton
  25. android:id="@+id/d3"
  26. android:layout_weight="1"
  27. android:layout_width="wrap_content"
  28. android:layout_height="wrap_content"
  29. android:src="@drawable/main_map_mode_3d_normal"
  30. >
  31. </ImageButton>
  32. </LinearLayout>

自定义对话框覆写Activity的oncreatDialog()方法———核心代码

  1. //自定义窗口(覆写 activity的oncreatedialog())
  2. @Override
  3. public Dialog onCreateDialog(int id) {
  4. // TODO Auto-generated method stub
  5. AlertDialog.Builder builder =new AlertDialog.Builder(this);
  6. final AlertDialog customDialog;
  7. LayoutInflater inflater = getLayoutInflater();
  8. View layout = inflater.inflate(R.layout.dialog, null);
  9. builder.setTitle("地图类型选择");
  10. builder.setView(layout);
  11. customDialog=builder.create();
  12. //相关点击事件处理
  13. //卫星地图
  14. ImageButton satellite=(ImageButton) layout.findViewById(R.id.satellite);
  15. satellite.setOnClickListener(new OnClickListener(){
  16. @Override
  17. public void onClick(View v) {
  18. // TODO Auto-generated method stub
  19. tager_map_type=0;
  20. Message message=new Message();
  21. Bundle bundle=new Bundle();
  22. bundle.putInt("target_map_type", tager_map_type);
  23. message.setData(bundle);
  24. message.what=2;
  25. handler.sendMessage(message);
  26. //自定义对话框关闭
  27. customDialog.cancel();
  28. }
  29. });
  30. //平面地图
  31. ImageButton plain=(ImageButton) layout.findViewById(R.id.plain);
  32. plain.setOnClickListener(new OnClickListener(){
  33. @Override
  34. public void onClick(View v) {
  35. // TODO Auto-generated method stub
  36. tager_map_type=1;
  37. Message message=new Message();
  38. Bundle bundle=new Bundle();
  39. bundle.putInt("target_map_type", tager_map_type);
  40. message.setData(bundle);
  41. message.what=2;
  42. handler.sendMessage(message);
  43. //自定义对话框关闭
  44. customDialog.cancel();
  45. }
  46. });
  47. //3d地图
  48. ImageButton d3=(ImageButton) layout.findViewById(R.id.d3);
  49. d3.setOnClickListener(new OnClickListener(){
  50. @Override
  51. public void onClick(View v) {
  52. // TODO Auto-generated method stub
  53. tager_map_type=2;
  54. Message message=new Message();
  55. Bundle bundle=new Bundle();
  56. bundle.putInt("target_map_type", tager_map_type);
  57. message.setData(bundle);
  58. message.what=2;
  59. handler.sendMessage(message);
  60. //自定义对话框关闭
  61. customDialog.cancel();
  62. }
  63. });
  64. return customDialog;
  65. }

MapView浮点按钮功能实现:

  1. //是否显示路况信息标识
  2. private boolean target_traffic=true;
  3. //显示地图类型(0:卫星地图、1:平面地图、2:3d地图)
  4. private int tager_map_type=1;
  5. //功能代码的编写
  6. public void params(){
  7. //交通类型
  8. Button traffic=(Button) findViewById(R.id.traffic);
  9. traffic.setOnClickListener(new OnClickListener(){
  10. @Override
  11. public void onClick(View v) {
  12. Message message=new Message();
  13. Bundle bundle=new Bundle();
  14. bundle.putBoolean("traffic",target_traffic);
  15. message.setData(bundle);
  16. message.what=1;
  17. handler.sendMessage(message);
  18. }
  19. });
  20. //地图类型(卫星地图、平面地图和三维地图)
  21. Button type=(Button) findViewById(R.id.type);
  22. type.setOnClickListener(new OnClickListener(){
  23. @Override
  24. public void onClick(View v) {
  25. //showDialog方法触发Activity的onCreateDialog(){可以自定义对话框样式}
  26. showDialog(0);
  27. }
  28. });
  29. }

运行截图:

Center 1Center 2Center 3

发表评论

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

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

相关阅读