您的位置:首页 > 移动开发 > Android开发

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

2013-08-15 17:03 666 查看
截图效果:





布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:orientation="horizontal"
    android:background="#ffffff"
    >
    <!--卫星地图  -->
    <ImageButton
        android:id="@+id/satellite"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/main_map_mode_satellite_normal"        
        >   
    </ImageButton>
    <!--平面地图  -->

    <ImageButton
        android:id="@+id/plain"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/main_map_mode_plain_normal" />

    <!--3d地图  -->
        <ImageButton
        android:id="@+id/d3"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/main_map_mode_3d_normal"        
        >   
    </ImageButton>

</LinearLayout>


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

//自定义窗口(覆写 activity的oncreatedialog())
	@Override
	public Dialog onCreateDialog(int id) {
		// TODO Auto-generated method stub
		AlertDialog.Builder builder =new AlertDialog.Builder(this);  
		final AlertDialog customDialog;
		
		 LayoutInflater inflater = getLayoutInflater();   
		 View layout = inflater.inflate(R.layout.dialog, null);
		 builder.setTitle("地图类型选择");
		 builder.setView(layout);
		 customDialog=builder.create();
		 //相关点击事件处理
		 //卫星地图
		 ImageButton satellite=(ImageButton) layout.findViewById(R.id.satellite);
		 satellite.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				tager_map_type=0;
				Message message=new Message();
				Bundle bundle=new Bundle();
				bundle.putInt("target_map_type", tager_map_type);
				message.setData(bundle);
				message.what=2;
				handler.sendMessage(message);
				//自定义对话框关闭
				customDialog.cancel();
			}
			 
		 });
		 //平面地图
		 ImageButton plain=(ImageButton) layout.findViewById(R.id.plain);
		 plain.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				tager_map_type=1;
				Message message=new Message();
				Bundle bundle=new Bundle();
				bundle.putInt("target_map_type", tager_map_type);
				message.setData(bundle);
				message.what=2;
				handler.sendMessage(message);
				//自定义对话框关闭
				customDialog.cancel();
			}
			 
		 });
		 //3d地图
		 ImageButton d3=(ImageButton) layout.findViewById(R.id.d3);
		 d3.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				tager_map_type=2;
				Message message=new Message();
				Bundle bundle=new Bundle();
				bundle.putInt("target_map_type", tager_map_type);
				message.setData(bundle);
				message.what=2;
				handler.sendMessage(message);
				//自定义对话框关闭
				customDialog.cancel();
			}
			 
		 });		
		
		return customDialog;
	}


MapView浮点按钮功能实现:

//是否显示路况信息标识
		private boolean target_traffic=true;
		//显示地图类型(0:卫星地图、1:平面地图、2:3d地图)
		private int tager_map_type=1;
	//功能代码的编写
	public void params(){
		//交通类型
		Button traffic=(Button) findViewById(R.id.traffic);
		traffic.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				Message message=new Message();
				Bundle bundle=new Bundle();
				bundle.putBoolean("traffic",target_traffic);
				message.setData(bundle);
				message.what=1;
			    handler.sendMessage(message);				
			}
			
		});
		//地图类型(卫星地图、平面地图和三维地图)
		Button type=(Button) findViewById(R.id.type);
		type.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				//showDialog方法触发Activity的onCreateDialog(){可以自定义对话框样式}
				 showDialog(0);
				
			}
			
		});
		
	}


运行截图:





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: