android 基于高德地图的轨迹回放
前段时间公司项目有一个需求,就是需要看到设备上传之后的轨迹路线,并且可以实现回放的整个过程,功能包括路线回放、地图位置插点、回放之后的轨迹标记颜色、回放加速等功能。下面是开发的整个过程。
首先,轨迹回放是基于地图做的,我这里用的是高德地图,轨迹回放是基于高德地图3D地图开发的,2D地图好像暂时不支持。必要的就是申请高德地图的key,然后配置到自己的项目里,这一步就不说了,高德地图上这些步骤很详细,也很简单,直接跳过到开发轨迹回放这一步。
首先上一个效果图:
开始回放 轨迹地图页面接下来是先接入地图,初始化整个地图,这一步也直接跳过吧,我最后会把整个代码贴出来,如果有需要可以自己看看,直接说轨迹回放在地图上划线的代码:
首先,新建一个存放经纬度的数组:
List<LatLng> points = new ArrayList<LatLng>();
然后把你获取到的经纬度add到数组里面
//添加经纬度至数组,添加下标,防止新数据占用老数据位置
points.add(i, new LatLng(latitude, longitude));
接下来就是用获取到的经纬度在地图上添加海量的marker点:
//添加海量marker点
MarkerOptions markerOption= new MarkerOptions();
// markerOption.position(new LatLng(aLocation.getLatitude(), aLocation.getLongitude()));
markerOption.position(new LatLng(latitude, longitude));
markerOption.visible(true);//标记可见
markerOption.icon(
BitmapDescriptorFactory.fromBitmap(BitmapFactory
.decodeResource(getResources(),
R.drawable.marker_blue)));
markerOption.anchor(0.5f, 0.5f);
Marker marker= aMap.addMarker(markerOption);
// marker.setIcon();
marker.setObject(map);// 这里可以存储用户数据
listMarker.add(marker);
然后在地图上划线,就是把points的点连接起来:
/*划线*/
private void showline() {
addPolylineInPlayGround();
Log.e("tag", points.toString());
// 获取轨迹坐标点
LatLngBounds.Builder b= LatLngBounds.builder();
for (int i= 0; i< points.size(); i++) {
b.include(points.get(i));
}
LatLngBounds bounds= b.build();
aMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
}
/*添加线条*/
private void addPolylineInPlayGround() {
List list= points;
List colorList= new ArrayList();
aMap.addPolyline(new PolylineOptions().setCustomTexture(BitmapDescriptorFactory.fromResource(R.drawable.custtexture)) //setCustomTextureList(bitmapDescriptors)
.addAll(list)
.useGradient(true)
.width(18));
}
现在线已经画好的,然后就可以进行轨迹回放以及暂停,销毁,加速的这些步骤:
/*开始移动*/
public void startMove() {
final PolylineOptions options= new PolylineOptions();
State = 1;
playback = 1;
play.setVisibility(View.GONE);
Fast_forward.setVisibility(View.VISIBLE);
stop.setVisibility(View.VISIBLE);
tingzhi.setVisibility(View.VISIBLE);
// 设置滑动的图标
smoothMarker.setDescriptor(BitmapDescriptorFactory.fromResource(R.mipmap.carr));
/*//当移动Marker的当前位置不在轨迹起点,先从当前位置移动到轨迹上,再开始平滑移动 // LatLng drivePoint = points.get(0);//设置小车当前位置,可以是任意点,这里直接设置为轨迹起点 LatLng drivePoint = new LatLng(39.980521,116.351905);//设置小车当前位置,可以是任意点Pair pair = PointsUtil.calShortestDistancePoint(points, drivePoint);
points.set(pair.first, drivePoint);
List subList = points.subList(pair.first, points.size());
// 设置滑动的轨迹左边点smoothMarker.setPoints(subList);*/
//计算轨迹运行之后的距离,重新开始回放
smoothMarker.setPoints(points);//设置平滑移动的轨迹list
// 设置移动的监听事件 返回 距终点的距离 单位 米
smoothMarker.setMoveListener(new SmoothMoveMarker.MoveListener() {
@Override
public void move(final double distance) {
runOnUiThread(new Runnable() {
@Override
public void run() {
//添加快进按钮,回放速度快进一倍
if (speed == 1) {
if ((int) distance > 1500000) {
smoothMarker.setTotalDuration(500);//设置平滑移动的总时间
}
if ((int) distance < 1500000 && (int) distance > 100000) {
smoothMarker.setTotalDuration(400);//设置平滑移动的总时间
}
if ((int) distance < 100000 && (int) distance > 50000) {
smoothMarker.setTotalDuration(250);//设置平滑移动的总时间
}
if ((int) distance < 50000 && (int) distance > 10000) {
smoothMarker.setTotalDuration(150);//设置平滑移动的总时间
}
if ((int) distance < 10000) {
smoothMarker.setTotalDuration(50);//设置平滑移动的总时间
}
} else {
//正常回放速度
if ((int) distance > 1500000) {
smoothMarker.setTotalDuration(1000);//设置平滑移动的总时间
}
if ((int) distance < 1500000 && (int) distance > 100000) {
smoothMarker.setTotalDuration(800);//设置平滑移动的总时间
}
if ((int) distance < 100000 && (int) distance > 50000) {
smoothMarker.setTotalDuration(500);//设置平滑移动的总时间
}
if ((int) distance < 50000 && (int) distance > 10000) {
smoothMarker.setTotalDuration(300);//设置平滑移动的总时间
}
if ((int) distance < 10000) {
smoothMarker.setTotalDuration(100);//设置平滑移动的总时间
}
}
if ((int) distance < 1) {
play.setVisibility(View.VISIBLE);
stop.setVisibility(View.GONE);
tingzhi.setVisibility(View.VISIBLE);
Fast_forward.setVisibility(View.GONE);
}
//获取当前的移动marker点,设置地图中心坐标点
LatLng position= smoothMarker.getPosition();
aMap.moveCamera(CameraUpdateFactory.changeLatLng(position));
redpoints.add(redpoints.size(), position);
aMap.addPolyline(options.color(Color.RED) //setCustomTextureList(bitmapDescriptors)
.add(position)
.useGradient(true)
.visible(true)
.width(18));
}
});
}
});
//设置地图缩放比例
aMap.moveCamera(CameraUpdateFactory.zoomTo(17));
smoothMarker.startSmoothMove();
smoothMarker.getMarker().setVisible(true);
}
/*停止平滑移动*/
public void stopMove() {
State = 2;
playback = 2;
smoothMarker.stopMove();
LatLng position1= smoothMarker.getPosition();
//暂停之后重新开始回放,继续之前的路径
// smoothMarker.startSmoothMove();
play.setVisibility(View.VISIBLE);
stop.setVisibility(View.GONE);
tingzhi.setVisibility(View.VISIBLE);
Fast_forward.setVisibility(View.GONE);
}
/*继续中断的轨迹回放路线*/
public void startmove() {
State = 3;
play.setVisibility(View.GONE);
stop.setVisibility(View.VISIBLE);
Fast_forward.setVisibility(View.VISIBLE);
tingzhi.setVisibility(View.VISIBLE);
smoothMarker.startSmoothMove();
}
/*停止轨迹回放*/
public void cease() {
State = 4;
playback = 3;
smoothMarker.destroy();
play.setVisibility(View.VISIBLE);
stop.setVisibility(View.GONE);
tingzhi.setVisibility(View.GONE);
Fast_forward.setVisibility(View.GONE);
aMap.clear();
points.clear();
}
正常的轨迹回放需求就是这些,如果没有任何问题的话,轨迹回放以及快进的功能已经做好了,在这里说一下我的经纬度信息是从百度鹰眼上获取到的,所以不用进行轨迹纠偏,所以这一步骤我也没有详细的研究,大概误差不会太高。要注意的一点就是给经纬度数组add数据的时候一定要添加下标,不然新的数组会添加到老数据之前,这样就会造成轨迹回放的时候会先从最后的一段路线开始,结束的时候是第一段路线,所以这里一定要注意。还有一个小小的问题就是有时候进入页面的时候路线还是有一点小问题,暂时我还没想到解决的办法,欢迎指正。下面是我整个页面的详细代码:
public class MapActivity extends Activity implements View.OnClickListener, AMap.OnMarkerClickListener {
private List points = new ArrayList();
private List redpoints = new ArrayList();
private LinearLayout infoWindowLayout, linear3;
private TextView title;
private TextView snippet;
private MapBean mapbean;
private LayoutInflater factory;
private MarkerOptions markerOption;
private MapView mapView;
private AMap aMap;
private OkHttpClient okHttpClient;
private Handler mHandler = new Handler();
private ImageView play, stop, massage, tingzhi, Fast_forward;
private SmoothMoveMarker smoothMarker;
private PopupWindow popupWindow;
private CustomPopWindow popupWindow1;
private String username, key, current_timestamp, type, number, strttime, endtime, url, sensor, Alarmtime, id;
private ImageView back;
private List list;
private String Smessage;
private ProgressDialogEx progressDlgEx;
private int State, playback;
private List listMarker = new ArrayList();
private int speed = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
progressDlgEx = new ProgressDialogEx(this, mHandler);
factory = LayoutInflater.from(MapActivity.this);
play = (ImageView) this.findViewById(R.id.play);
stop = (ImageView) this.findViewById(R.id.stop);
massage = (ImageView) this.findViewById(R.id.massage);
massage.setOnClickListener(this);
back = (ImageView) this.findViewById(R.id.back);
back.setOnClickListener(this);
play = (ImageView) this.findViewById(R.id.play);
play.setOnClickListener(this);
stop = (ImageView) this.findViewById(R.id.stop);
stop.setOnClickListener(this);
tingzhi = (ImageView) this.findViewById(R.id.tingzhi);
tingzhi.setOnClickListener(this);
Fast_forward = (ImageView) this.findViewById(R.id.Fast_forward);
Fast_forward.setOnClickListener(this);
// 获取用户名
username = SharedPreferencesUtils.getString(MapActivity.this, "userName", "");
key = Data.getInstance().key;
//时间戳
current_timestamp = Data.getInstance().current_timestamp;
Intent intent= getIntent();
type = intent.getStringExtra("type");//设备类型 1冷藏车 2保温箱
number = intent.getStringExtra("number");//设备号 车牌号或保温箱号
strttime = intent.getStringExtra("strttime");//开始时间
endtime = intent.getStringExtra("endtime");//结束时间
sensor = intent.getStringExtra("sensor");//sensor
id = intent.getStringExtra("id");
mapView = (MapView) findViewById(R.id.map);
mapView.onCreate(savedInstanceState);// 此方法必须重写
init();
DeviceWorkTime();
ShowMessage();
}
/*比较时间截取,分割时间不大于24小时*/
private void CycleTime(String num, int startdate, int enddate) {
//相差6天以上
if (enddate- startdate>= 518400) {
String onetime= String.valueOf(enddate- 86399);
String twotime= String.valueOf(Integer.parseInt(onetime) - 86399);
String thretime= String.valueOf(Integer.parseInt(twotime) - 86399);
String foretime= String.valueOf(Integer.parseInt(threetime) - 86399);
String fivetime= String.valueOf(Integer.parseInt(foretime) - 86399);
String sixtime= String.valueOf(Integer.parseInt(fivetime) - 86399);
//strttime,sixtime sixtime,fivetime fivetime,foretime foretime,threetime threetime,twotime twotime,onetime onetime,endtime
show(num, String.valueOf(startdate), sixtime);
show(num, sixtime, fivetime);
show(num, fivetime, foretime);
show(num, foretime, threetime);
show(num, threetime, twotime);
show(num, twotime, onetime);
show(num, onetime, String.valueOf(enddate));
}
//小于1天
else if (enddate- startdate< 86400) {
show(num, String.valueOf(startdate), String.valueOf(enddate));
}
}
/*获取设备工作时间段*/
private void DeviceWorkTime() {
points.clear();
new Thread() {
@Override
public void run() {
progressDlgEx.simpleModeShowHandleThread();
OkHttpClient okHttpClient= new OkHttpClient();
String format= String.format(KeyPath.Path.head + KeyPath.Path.deviceworktime, username, key, current_timestamp, type, strttime, endtime, id);
Request build1= new Request.Builder().url(format).build();
okHttpClient.newCall(build1).enqueue(new Callback() {
@Overrid
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String string= response.body().string();
if (string!= null) {
try {
final JSONObject jsonObject= new JSONObject(string);
int status= jsonObject.getInt("status");
if (status== 1) {
mHandler.post(new Runnable() {
@Override
public void run() {
try {
JSONObject data= jsonObject.getJSONObject("data");
JSONArray items= data.getJSONArray("device");
final List listt= JsonUtils.parseJsonArray(items);
Data.getInstance().list = listt;
for (int i= 0; i< listt.size(); i++) {
Map map= (Map) listt.get(i);
String boxmac= map.get("boxmac").toString();
int startdate= Integer.parseInt(map.get("startdate").toString());
int enddate= Integer.parseInt(map.get("enddate").toString());
CycleTime(boxmac, startdate, enddate);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
} catch (JSONException e) {
e.printStackTrace();
} finally {
progressDlgEx.closeHandleThread();
}
}
}
});
}
}.start();
}
/**
* 初始化AMap对象
*/
private void init() {
if (aMap == null) {
aMap = mapView.getMap();
}
aMap.setOnMarkerClickListener(this);// 设置点击marker事件监听器
smoothMarker = new SmoothMoveMarker(aMap);
}
/**
* 方法必须重写
*/
@Override
protected void onResume() {
super.onResume();
mapView.onResume()
}
/**
* 方法必须重写
*/
@Override
protected void onPause() {
super.onPause();
mapView.onPause();
}
/**
* 方法必须重写
*/
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
/**
* 方法必须重写
*/
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
/*划线*/
private void showline() {
addPolylineInPlayGround();
Log.e("tag", points.toString());
// 获取轨迹坐标点
LatLngBounds.Builder b= LatLngBounds.builder();
for (int i= 0; i< points.size(); i++) {
b.include(points.get(i));
}
LatLngBounds bounds= b.build();
aMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
}
/*开始移动*/
public void startMove() {
final PolylineOptions options= new PolylineOptions();
State = 1;
playback = 1;
play.setVisibility(View.GONE);
Fast_forward.setVisibility(View.VISIBLE);
stop.setVisibility(View.VISIBLE);
tingzhi.setVisibility(View.VISIBLE);
// 设置滑动的图标
smoothMarker.setDescriptor(BitmapDescriptorFactory.fromResource(R.mipmap.carr));
/*//当移动Marker的当前位置不在轨迹起点,先从当前位置移动到轨迹上,再开始平滑移动 // LatLng drivePoint = points.get(0);//设置小车当前位置,可以是任意点,这里直接设置为轨迹起点 LatLng drivePoint = new LatLng(39.980521,116.351905);//设置小车当前位置,可以是任意点Pair pair = PointsUtil.calShortestDistancePoint(points, drivePoint);
points.set(pair.first, drivePoint);
List subList = points.subList(pair.first, points.size());
// 设置滑动的轨迹左边点smoothMarker.setPoints(subList);*/
//计算轨迹运行之后的距离,重新开始回放
smoothMarker.setPoints(points);//设置平滑移动的轨迹list
// 设置移动的监听事件 返回 距终点的距离 单位 米
smoothMarker.setMoveListener(new SmoothMoveMarker.MoveListener() {
@Override
public void move(final double distance) {
runOnUiThread(new Runnable() {
@Override
public void run() {
//添加快进按钮,回放速度快进一倍
if (speed == 1) {
if ((int) distance > 1500000) {
smoothMarker.setTotalDuration(500);//设置平滑移动的总时间
}
if ((int) distance < 1500000 && (int) distance > 100000) {
smoothMarker.setTotalDuration(400);//设置平滑移动的总时间
}
if ((int) distance < 100000 && (int) distance > 50000) {
smoothMarker.setTotalDuration(250);//设置平滑移动的总时间
}
if ((int) distance < 50000 && (int) distance > 10000) {
smoothMarker.setTotalDuration(150);//设置平滑移动的总时间
}
if ((int) distance < 10000) {
smoothMarker.setTotalDuration(50);//设置平滑移动的总时间
}
} else {
//正常回放速度
if ((int) distance > 1500000) {
smoothMarker.setTotalDuration(1000);//设置平滑移动的总时间
}
if ((int) distance < 1500000 && (int) distance > 100000) {
smoothMarker.setTotalDuration(800);//设置平滑移动的总时间
}
if ((int) distance < 100000 && (int) distance > 50000) {
smoothMarker.setTotalDuration(500);//设置平滑移动的总时间
}
if ((int) distance < 50000 && (int) distance > 10000) {
smoothMarker.setTotalDuration(300);//设置平滑移动的总时间
}
if ((int) distance < 10000) {
smoothMarker.setTotalDuration(100);//设置平滑移动的总时间
}
}
if ((int) distance < 1) {
play.setVisibility(View.VISIBLE);
stop.setVisibility(View.GONE);
tingzhi.setVisibility(View.VISIBLE);
Fast_forward.setVisibility(View.GONE);
// aMap.clear();
// points.clear();
// options.addAll(redpoints);
// showline();
// DeviceWorkTime();
}
//获取当前的移动marker点,设置地图中心坐标点
LatLng position= smoothMarker.getPosition();
aMap.moveCamera(CameraUpdateFactory.changeLatLng(position));
redpoints.add(redpoints.size(), position);
// options.addAll(redpoints);
// options.add(position);
// options.width(18);
// options.useGradient(true);
// options.color(Color.RED);
// aMap.addPolyline(options);
aMap.addPolyline(options.color(Color.RED) //setCustomTextureList(bitmapDescriptors)
.add(position)
.useGradient(true)
.visible(true)
.width(18));
}
});
}
});
//设置地图缩放比例
aMap.moveCamera(CameraUpdateFactory.zoomTo(17));
smoothMarker.startSmoothMove();
smoothMarker.getMarker().setVisible(true);
}
/*停止平滑移动*/
public void stopMove() {
State = 2;
playback = 2;
smoothMarker.stopMove();
LatLng position1= smoothMarker.getPosition();
//暂停之后重新开始回放,继续之前的路径
// smoothMarker.startSmoothMove();
play.setVisibility(View.VISIBLE);
stop.setVisibility(View.GONE);
tingzhi.setVisibility(View.VISIBLE);
Fast_forward.setVisibility(View.GONE);
}
/*继续中断的轨迹回放路线*/
public void startmove() {
State = 3;
play.setVisibility(View.GONE);
stop.setVisibility(View.VISIBLE);
Fast_forward.setVisibility(View.VISIBLE);
tingzhi.setVisibility(View.VISIBLE);
smoothMarker.startSmoothMove();
}
/*停止轨迹回放*/
public void cease() {
State = 4;
playback = 3;
smoothMarker.destroy();
play.setVisibility(View.VISIBLE);
stop.setVisibility(View.GONE);
tingzhi.setVisibility(View.GONE);
Fast_forward.setVisibility(View.GONE);
aMap.clear();
points.clear();
DeviceWorkTime();
// List colorList = new ArrayList();
// aMap.addPolyline(options.setCustomTexture(BitmapDescriptorFactory.fromResource(R.drawable.custtexture)) //setCustomTextureList(bitmapDescriptors)
// .addAll(points)
// .useGradient(true)
// .width(18));
}
/*添加线条*/
private void addPolylineInPlayGround() {
List list= points;
List colorList= new ArrayList();
aMap.addPolyline(new PolylineOptions().setCustomTexture(BitmapDescriptorFactory.fromResource(R.drawable.custtexture)) //setCustomTextureList(bitmapDescriptors)
.addAll(list)
.useGradient(true)
.width(18));
}
/*百度鹰眼接口返回经纬度数据*/
public void show(final String num, final String strttime, final String endtime) {
new Thread() {
@Override
public void run() {
progressDlgEx.simpleModeShowHandleThread();
OkHttpClient okHttpClient= new OkHttpClient();
//这里是百度鹰眼的接口,为了不造成麻烦,我就不发出去了
Request build1= new Request.Builder().url(format).build();
okHttpClient.newCall(build1).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String string= response.body().string();
if (string!= null) {
try {
final JSONObject jsonObject= new JSONObject(string);
int status= jsonObject.getInt("status");
if (status== 0) {
mHandler.post(new Runnable() {
@Override
public void run() {
try {
JSONArray pointss= jsonObject.getJSONArray("points");
final List listt= JsonUtils.parseJsonArray(pointss);
for (int i= 0; i< listt.size(); i++) {
Map map= (Map) listt.get(i);
final double latitude= Double.parseDouble(map.get("latitude").toString());
final double longitude= Double.parseDouble(map.get("longitude").toString());
final String address= map.get("address").toString();
final int loc_time= Integer.parseInt(map.get("loc_time").toString());
//
//添加经纬度至数组,添加下标,防止新数据占用老数据位置
points.add(i, new LatLng(latitude, longitude));
//添加海量marker点
MarkerOptions markerOption= new MarkerOptions();
// markerOption.position(new LatLng(aLocation.getLatitude(), aLocation.getLongitude()));
markerOption.position(new LatLng(latitude, longitude));
markerOption.visible(true);//标记可见
markerOption.icon(
BitmapDescriptorFactory.fromBitmap(BitmapFactory
.decodeResource(getResources(),
R.drawable.marker_blue)));
markerOption.anchor(0.5f, 0.5f);
Marker marker= aMap.addMarker(markerOption);
// marker.setIcon();
marker.setObject(map);// 这里可以存储用户数据
listMarker.add(marker);
}
showline();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
} catch (JSONException e) {
e.printStackTrace();
} finally {
progressDlgEx.closeHandleThread();
}
}
}
});
}
}.start();
}
/**
* 点击Marker
*/
public boolean onMarkerClick(Marker arg0) {
// TODO Auto-generated method stub
// String streenName = "中山路";
Map map= (Map) arg0.getObject();
final double latitude= Double.parseDouble(map.get("latitude").toString());
final double longitude= Double.parseDouble(map.get("longitude").toString());
final String address= map.get("address").toString();
final int loc_time= Integer.parseInt(map.get("loc_time").toString());
// arg0.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.purple_pin));
arg0.setTitle("详细信息");
ShowSensor(String.valueOf(loc_time), latitude, longitude, address);
return false;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.Fast_forward:
DialogUtils.showPopMsgInHandleThread(MapActivity.this, mHandler, "快进一倍回放!");
Fast_forward.setVisibility(View.GONE);
speed = 1;
break;
case R.id.back:
finish();
points.clear();
break;
case R.id.play:
if (points.size() < 1) {
Toast.makeText(MapActivity.this, MapActivity.this.getString(R.string.zwjl), Toast.LENGTH_SHORT).show();
} else {
if (playback == 1) {
DialogUtils.showPopMsgInHandleThread(MapActivity.this, mHandler, "请先停止轨迹回放路线!");
return;
} else {
DialogUtils.showPopMsgInHandleThread(MapActivity.this, mHandler, "开始回放轨迹路线!");
speed = 0;
if (State == 2) {
startmove();
} else {
startMove();
}
}
}
break;
case R.id.stop:
DialogUtils.showPopMsgInHandleThread(MapActivity.this, mHandler, "暂停轨迹回放!");
speed = 0;
stopMove();
break;
case R.id.tingzhi:
DialogUtils.showPopMsgInHandleThread(MapActivity.this, mHandler, "停止轨迹回放!");
cease();
break;
case R.id.massage:
if (points.size() < 1) {
Toast.makeText(MapActivity.this, MapActivity.this.getString(R.string.zwjl), Toast.LENGTH_SHORT).show();
} else {
if (popupWindow != null && popupWindow.isShowing()) {
return;
}
LinearLayout layout= (LinearLayout) getLayoutInflater().inflate(R.layout.map_pop, null);
popupWindow = new PopupWindow(layout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//点击空白处时,隐藏掉pop窗口
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
//添加弹出、弹入的动画
popupWindow.setAnimationStyle(R.style.Popupwindow);
int[] location= new int[2];
massage.getLocationOnScreen(location);
popupWindow.showAtLocation(massage, Gravity.CENTER | Gravity.BOTTOM, 0, -location[1]);
//添加按键事件监听
//setButtonListeners(layout);
//添加pop窗口关闭事件,主要是实现关闭时改变背景的透明度
//popupWindow.setOnDismissListener(new poponDismissListener());
//backgroundAlpha(1f);
linear3 = (LinearLayout) layout.findViewById(R.id.linear3);
for (int i= 0; i< Data.getInstance().list.size(); i++) {
Map map= (Map) Data.getInstance().list.get(i);
String boxmac= map.get("boxmac").toString();
int startdate= Integer.parseInt(map.get("startdate").toString());
int enddate= Integer.parseInt(map.get("enddate").toString());
SplitTime(boxmac, startdate, enddate);
Log.e("TAG", boxmac+ startdate+ enddate);
}
}
break;
default:
break;
}
}
}
网友评论