1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > android高德地图自定义地图 (android地图开发) 高德地图自定义对话框

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

时间:2020-07-16 14:34:35

相关推荐

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

截图效果:

布局文件:

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="horizontal"

android:background="#ffffff"

>

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"

>

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" />

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"

>

自定义对话框覆写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);

}

});

}

运行截图:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。