分类:C#、Android、VS2015、百度地图应用; 创建日期:2016-02-04

一、简介

周边雷达功能同步支持Android和iOS端。它本质是一个连接百度LBS开放平台前端SDK产品和后端LBS云的中间服务。开发者利用周边雷达功能,可以便捷的在自己的应用内,帮助用户实现查找周边跟“我”使用同样一款App的人这样一个功能。或者说,利用周边雷达功能,开发者可在App内低成本、快速实现查找周边使用相同App的用户位置。

1、周边雷达功能的典型使用场景

(1)查看周边都有谁跟“我”使用同一个App,分布在哪里?

(2)查看周边用户在听什么歌、看什么文章、有什么新动态?

(3)查看周边有什么最新发生的新闻、资讯?

2、使用周边雷达功能的流程

使用周边雷达功能的流程如下:

第一步、注册周边雷达

在使用周边雷达功能之前,需要对应用的密钥(Key)做相应的注册操作。周边雷达支持应用位置信息上传,及一个或多个应用之间实现相互的位置信息查看功能。

第二步、集成SDK

周边雷达是地图SDK产品的一个功能模块,需要使用周边雷达功能的开发者,需在官网下载包含周边雷达功能的地图SDK,并将其集成到自己的开发环境中即可。

具体SDK集成方式请参考《开发指南 – 配置环境及发布》章节的介绍。

第三步、开发

完成周边雷达注册和SDK集成后,即可开始具体功能的开发工作。

具体使用方法请参考后文的详细介绍及官方Demo示例。

二、运行截图

简介:介绍如果使用周边雷达功能上传位置、检索周边的人

详述:

(1)获取位置信息并单次上传服务端;

(2)获取位置信息连续上传服务端;

(3)检索周边用户的位置;

(4)用列表的形式及地图的形式展示周边用户的位置等信息;

注意:需要把应用的key在官网的雷达注册页面进行相关的注册才能使用!

注册网址:http://developer.baidu.com/map/index.php?title=radar

本示例运行截图如下:

三、设计步骤

1、在雷达注册页面中注册key

进入官网的雷达注册页面,用原来申请的key注册雷达定位服务。

2、添加demo17_radarlist.xml文件

在layout文件夹下添加该文件,然后将代码改为下面的内容:

(略)

3、添加demo17_radarmap.xml文件

在layout文件夹下添加该文件,然后将代码改为下面的内容:

(略)

4、添加demo17_radartablayout.xml文件

在layout文件夹下添加该文件,然后将代码改为下面的内容:

(略)

5、添加Demo17CustomViewPager.cs文件

在SrcSdkDemos文件夹下添加该文件,然后将代码改为下面的内容:

  1. using Android.App;
  2. using Android.Content;
  3. using Android.Support.V4.View;
  4. using Android.Util;
  5. using Android.Views;
  6. namespace BdMapV371Demos.SrcSdkDemos
  7. {
  8. [Activity(Label = "@string/demo_name_share")]
  9. public class Demo17CustomViewPager : ViewPager
  10. {
  11. private bool isCanScroll = false;
  12. public Demo17CustomViewPager(Context context) : base(context)
  13. { }
  14.  
  15. public Demo17CustomViewPager(Context context, IAttributeSet attrs)
  16. : base(context, attrs)
  17. { }
  18.  
  19. public void SetScanScroll(bool isCanScroll)
  20. {
  21. this.isCanScroll = isCanScroll;
  22. }
  23.  
  24. public override void ScrollTo(int x, int y)
  25. {
  26. base.ScrollTo(x, y);
  27. }
  28.  
  29. public override void SetCurrentItem(int item, bool smoothScroll)
  30. {
  31. base.SetCurrentItem(item, smoothScroll);
  32. }
  33.  
  34. public override bool OnTouchEvent(MotionEvent e)
  35. {
  36. if (isCanScroll)
  37. {
  38. return base.OnTouchEvent(e);
  39. }
  40. else
  41. {
  42. return false;
  43. }
  44. }
  45.  
  46. public override bool OnInterceptTouchEvent(MotionEvent ev)
  47. {
  48. if (isCanScroll)
  49. {
  50. return base.OnInterceptTouchEvent(ev);
  51. }
  52. else {
  53. return false;
  54. }
  55. }
  56. }
  57. }

6、添加Demo17Radar.cs文件

在SrcSdkDemos文件夹下添加该文件,然后将代码改为下面的内容:

  1. using Android.App;
  2. using Android.Content.PM;
  3. using Android.OS;
  4. using Android.Util;
  5. using Android.Text;
  6. using Android.Views;
  7. using Android.Widget;
  8. using Android.Graphics;
  9. using Com.Baidu.Location;
  10. using Com.Baidu.Mapapi.Map;
  11. using Com.Baidu.Mapapi.Model;
  12. using Com.Baidu.Mapapi.Radar;
  13. using Android.Support.V4.View;
  14. using System.Collections.Generic;
  15.  
  16. namespace BdMapV371Demos.SrcSdkDemos
  17. {
  18. /// <summary>
  19. /// 演示周边雷达的业务场景使用
  20. /// </summary>
  21. [Activity(Label = "@string/demo_name_radar",
  22. ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,
  23. ScreenOrientation = ScreenOrientation.Sensor)]
  24. public class Demo17Radar : Activity,
  25. IRadarUploadInfoCallback,
  26. IRadarSearchListener,
  27. IBDLocationListener
  28. {
  29. #region 界面空间相关
  30. private Demo17CustomViewPager mPager;//自定义viewPager,目的是禁用手势滑动
  31. private List<View> listViews;
  32. private TabHost mTabHost;
  33. private EditText userId;
  34. private EditText userDes;
  35. private Button uploadOnece;
  36. private Button uploadContinue;
  37. private Button stopUpload;
  38. private Button switchBtn;
  39. private Button searchNearbyBtn;
  40. private Button clearRstBtn;
  41. private Button clearInfoBtn;
  42. private int index = ;
  43. private Button listPreBtn;
  44. private Button listNextBtn;
  45. private TextView listCurPage;
  46. private Button mapPreBtn;
  47. private Button mapNextBtn;
  48. private TextView mapCurPage;
  49. #endregion
  50.  
  51. #region 定位相关
  52. LocationClient mLocClient;
  53. private int pageIndex = ;
  54. private int curPage = ;
  55. private int totalPage = ;
  56. private LatLng pt = null;
  57. #endregion
  58.  
  59. #region 周边雷达相关
  60. RadarNearbyResult listResult = null;
  61. ListView mResultListView = null;
  62. RadarResultListAdapter mResultListAdapter = null;
  63. private string userID = "";
  64. private string userComment = "";
  65. private bool uploadAuto = false;
  66. #endregion
  67.  
  68. #region 地图相关
  69. private TextureMapView mMapView;
  70. private BaiduMap mBaiduMap;
  71. private TextView popupText = null;//泡泡view
  72. BitmapDescriptor ff3 = BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_marka);
  73. #endregion
  74.  
  75. protected override void OnCreate(Bundle savedInstanceState)
  76. {
  77. base.OnCreate(savedInstanceState);
  78. SetContentView(Resource.Layout.demo17_radartablayout);
  79.  
  80. //初始化UI和地图
  81. InitUI();
  82.  
  83. //周边雷达设置监听
  84. RadarSearchManager.Instance.AddNearbyInfoListener(this);
  85. //周边雷达设置用户,id为空默认是设备标识
  86. RadarSearchManager.Instance.SetUserID(userID);
  87.  
  88. // 定位初始化
  89. mLocClient = new LocationClient(this);
  90. mLocClient.RegisterLocationListener(this);
  91. LocationClientOption option = new LocationClientOption();
  92. option.OpenGps = false; // 是否打开gps
  93. option.CoorType = "bd09ll"; // 设置坐标类型
  94. option.ScanSpan = ;
  95. mLocClient.LocOption = option;
  96. mLocClient.Start();
  97. }
  98.  
  99. private void InitUI()
  100. {
  101. mTabHost = FindViewById<TabHost>(Resource.Id.tabhost);
  102. mTabHost.Setup();
  103. mTabHost.AddTab(mTabHost.NewTabSpec("tabUpload")
  104. .SetIndicator(ComposeLayout("上传位置", ))
  105. .SetContent(Resource.Id.tabUpload));
  106. mTabHost.AddTab(mTabHost.NewTabSpec("tabGet")
  107. .SetIndicator(ComposeLayout("检索周边", ))
  108. .SetContent(Resource.Id.tabGet));
  109. mTabHost.CurrentTab = ;
  110. mTabHost.TabChanged += (s, e) =>
  111. {
  112. mTabHost.TabWidget.GetChildAt(mTabHost.CurrentTab).SetBackgroundColor(Color.ParseColor("#B0E2FF"));
  113. };
  114.  
  115. mPager = FindViewById<Demo17CustomViewPager>(Resource.Id.viewpager);
  116. listViews = new List<View>();
  117. View layout = LayoutInflater.Inflate(Resource.Layout.demo17_radarlist, null);
  118. View mapLayout = LayoutInflater.Inflate(Resource.Layout.demo17_radarmap, null);
  119. //地图初始化
  120. mMapView = mapLayout.FindViewById<TextureMapView>(Resource.Id.map);
  121. mBaiduMap = mMapView.Map;
  122. mBaiduMap.MarkerClick += (s, e) =>
  123. {
  124. var marker = e.P0;
  125. mBaiduMap.HideInfoWindow();
  126. if (marker != null)
  127. {
  128. popupText = new TextView(this);
  129. popupText.SetBackgroundResource(Resource.Drawable.popup);
  130. popupText.SetTextColor(Color.ParseColor("0xFF000000"));
  131. popupText.Text = marker.ExtraInfo.GetString("des");
  132. mBaiduMap.ShowInfoWindow(new InfoWindow(popupText, marker.Position, -));
  133. MapStatusUpdate update = MapStatusUpdateFactory.NewLatLng(marker.Position);
  134. mBaiduMap.SetMapStatus(update);
  135. }
  136. };
  137. mBaiduMap.MapClick += (s, e) =>
  138. {
  139. mBaiduMap.HideInfoWindow();
  140. };
  141. mBaiduMap.MyLocationEnabled = true;
  142. listViews.Add(layout);
  143. listViews.Add(mapLayout);
  144. mPager.Adapter = new MyPagerAdapter(listViews);
  145. mPager.CurrentItem = ;
  146. mPager.PageSelected += (s, e) =>
  147. {
  148. if (e.Position == ) //切换为列表
  149. {
  150. index = ;
  151. switchBtn.Text = "地图";
  152. }
  153. else //切换为地图
  154. {
  155. index = ;
  156. switchBtn.Text = "列表";
  157. }
  158. };
  159.  
  160. userId = FindViewById<EditText>(Resource.Id.id);
  161. userDes = FindViewById<EditText>(Resource.Id.des);
  162. //用户ID和用户描述文本框变化时引发的事件
  163. userId.TextChanged += User_TextChanged;
  164. userDes.TextChanged += User_TextChanged;
  165.  
  166. //【检索周边】按钮
  167. searchNearbyBtn = FindViewById<Button>(Resource.Id.searchNearByButton);
  168. searchNearbyBtn.Click += delegate
  169. {
  170. //查找周边的人
  171. if (pt == null)
  172. {
  173. Toast.MakeText(this, "未获取到位置", ToastLength.Long).Show();
  174. return;
  175. }
  176. pageIndex = ;
  177. SearchRequest(pageIndex);
  178. };
  179.  
  180. //【清除结果】按钮
  181. clearRstBtn = FindViewById<Button>(Resource.Id.clearResultButton);
  182. clearRstBtn.Click += delegate
  183. {
  184. //清除查找结果
  185. ParseResultToList(null);
  186. ParseResultToMap(null);
  187. clearRstBtn.Enabled = false;
  188. listPreBtn.Visibility = ViewStates.Invisible;
  189. listNextBtn.Visibility = ViewStates.Invisible;
  190. mapPreBtn.Visibility = ViewStates.Invisible;
  191. mapNextBtn.Visibility = ViewStates.Invisible;
  192. listCurPage.Visibility = ViewStates.Invisible;
  193. mapCurPage.Visibility = ViewStates.Invisible;
  194. mBaiduMap.HideInfoWindow();
  195. };
  196.  
  197. //【地图】按钮
  198. switchBtn = FindViewById<Button>(Resource.Id.switchButton);
  199. switchBtn.Click += delegate
  200. {
  201. //viewPager切换
  202. if (index == )
  203. {
  204. //切换为地图
  205. index = ;
  206. switchBtn.Text = "列表";
  207. }
  208. else {
  209. //切换为列表
  210. index = ;
  211. switchBtn.Text = "地图";
  212. }
  213. mPager.CurrentItem = index;
  214. };
  215.  
  216. //【获取当前位置并上传】按钮
  217. uploadOnece = FindViewById<Button>(Resource.Id.uploadonece);
  218. uploadOnece.Click += delegate
  219. {
  220. //上传一次位置
  221. if (pt == null)
  222. {
  223. Toast.MakeText(this, "未获取到位置", ToastLength.Long).Show();
  224. return;
  225. }
  226. RadarUploadInfo info = new RadarUploadInfo();
  227. info.Comments = userComment;
  228. info.Pt = pt;
  229. RadarSearchManager.Instance.UploadInfoRequest(info);
  230. clearInfoBtn.Enabled = true;
  231. };
  232.  
  233. //【连续获取位置并上传】按钮
  234. uploadContinue = FindViewById<Button>(Resource.Id.uploadcontinue);
  235. uploadContinue.Click += delegate
  236. {
  237. //开始自动上传
  238. if (pt == null)
  239. {
  240. Toast.MakeText(this, "未获取到位置", ToastLength.Long).Show();
  241. return;
  242. }
  243. uploadAuto = true;
  244. RadarSearchManager.Instance.StartUploadAuto(this, );
  245. uploadContinue.Enabled = false;
  246. stopUpload.Enabled = true;
  247. clearInfoBtn.Enabled = true;
  248. };
  249.  
  250. //【停止上传】按钮
  251. stopUpload = FindViewById<Button>(Resource.Id.stopupload);
  252. stopUpload.Click += delegate
  253. {
  254. //停止自动上传
  255. uploadAuto = false;
  256. RadarSearchManager.Instance.StopUploadAuto();
  257. stopUpload.Enabled = false;
  258. uploadContinue.Enabled = true;
  259. };
  260.  
  261. //【清除当前信息】按钮
  262. clearInfoBtn = FindViewById<Button>(Resource.Id.clearInfoButton);
  263. clearInfoBtn.Click += delegate
  264. {
  265. //清除自己当前的信息
  266. RadarSearchManager.Instance.ClearUserInfo();
  267. };
  268.  
  269. //--------layout--demo17_radarlist.xml----------------
  270. //【上一页】按钮
  271. listPreBtn = layout.FindViewById<Button>(Resource.Id.radarlistpre);
  272. listPreBtn.Click += delegate
  273. {
  274. if (pageIndex < ) return;
  275. pageIndex--;
  276. SearchRequest(pageIndex);
  277. };
  278.  
  279. //【下一页】按钮
  280. listNextBtn = layout.FindViewById<Button>(Resource.Id.radarlistnext);
  281. listNextBtn.Click += delegate
  282. {
  283. if (pageIndex >= totalPage - ) return;
  284. pageIndex++;
  285. SearchRequest(pageIndex);
  286. };
  287.  
  288. listCurPage = layout.FindViewById<TextView>(Resource.Id.radarListPage);
  289. mapPreBtn = mapLayout.FindViewById<Button>(Resource.Id.radarmappre);
  290. mapNextBtn = mapLayout.FindViewById<Button>(Resource.Id.radarmapnext);
  291. mapCurPage = mapLayout.FindViewById<TextView>(Resource.Id.radarMapPage);
  292.  
  293. uploadContinue.Enabled = true;
  294. stopUpload.Enabled = false;
  295. clearRstBtn.Enabled = false;
  296. clearInfoBtn.Enabled = false;
  297. listPreBtn.Visibility = ViewStates.Invisible;
  298. listNextBtn.Visibility = ViewStates.Invisible;
  299. mapPreBtn.Visibility = ViewStates.Invisible;
  300. mapNextBtn.Visibility = ViewStates.Invisible;
  301. listCurPage.Visibility = ViewStates.Invisible;
  302. mapCurPage.Visibility = ViewStates.Invisible;
  303.  
  304. mTabHost.TabWidget.GetChildAt().SetBackgroundColor(Color.DarkGray);
  305. List<RadarNearbyInfo> infos = new List<RadarNearbyInfo>();
  306. mResultListAdapter = new RadarResultListAdapter(this, infos);
  307. mResultListView = layout.FindViewById<ListView>(Resource.Id.radar_list);
  308. mResultListView.Adapter = mResultListAdapter;
  309. mResultListAdapter.NotifyDataSetChanged();
  310. }
  311.  
  312. private void User_TextChanged(object sender, TextChangedEventArgs e)
  313. {
  314. userID = userId.Text;
  315. userComment = userDes.Text;
  316. RadarSearchManager.Instance.SetUserID(userID);
  317. }
  318.  
  319. private void SearchRequest(int index)
  320. {
  321. curPage = ;
  322. totalPage = ;
  323.  
  324. RadarNearbySearchOption option = new RadarNearbySearchOption()
  325. .CenterPt(pt).PageNum(pageIndex).Radius();
  326. RadarSearchManager.Instance.NearbyInfoRequest(option);
  327.  
  328. listPreBtn.Visibility = ViewStates.Invisible;
  329. listNextBtn.Visibility = ViewStates.Invisible;
  330. mapPreBtn.Visibility = ViewStates.Invisible;
  331. mapNextBtn.Visibility = ViewStates.Invisible;
  332. listCurPage.Text = "0/0";
  333. mapCurPage.Text = "0/0";
  334. mBaiduMap.HideInfoWindow();
  335. }
  336.  
  337. /// <summary>
  338. /// 更新结果列表
  339. /// </summary>
  340. /// <param name="res"></param>
  341. public void ParseResultToList(RadarNearbyResult res)
  342. {
  343. if (res == null)
  344. {
  345. if (mResultListAdapter.list != null)
  346. {
  347. mResultListAdapter.list.Clear();
  348. mResultListAdapter.NotifyDataSetChanged();
  349. }
  350.  
  351. }
  352. else
  353. {
  354. mResultListAdapter.list.Clear();
  355. foreach (RadarNearbyInfo v in res.InfoList)
  356. {
  357. mResultListAdapter.list.Add(v);
  358. }
  359. mResultListAdapter.NotifyDataSetChanged();
  360. if (curPage > )
  361. {
  362. listPreBtn.Visibility = ViewStates.Visible;
  363. }
  364. if (totalPage - > curPage)
  365. {
  366. listNextBtn.Visibility = ViewStates.Visible;
  367. }
  368. if (totalPage > )
  369. {
  370. listCurPage.Visibility = ViewStates.Visible;
  371. listCurPage.Text = string.Format("{0}/{1}", curPage + , totalPage);
  372. }
  373. }
  374. }
  375.  
  376. /// <summary>
  377. ///更新结果地图
  378. /// </summary>
  379. /// <param name="res"></param>
  380. public void ParseResultToMap(RadarNearbyResult res)
  381. {
  382. mBaiduMap.Clear();
  383. if (res != null && res.InfoList != null && res.InfoList.Count > )
  384. {
  385. List<RadarNearbyInfo> v = new List<RadarNearbyInfo>();
  386. foreach (RadarNearbyInfo item in res.InfoList)
  387. {
  388. v.Add(item);
  389. }
  390. for (int i = ; i < v.Count; i++)
  391. {
  392. MarkerOptions option = new MarkerOptions()
  393. .InvokeIcon(ff3)
  394. .InvokePosition(v[i].Pt);
  395. Bundle des = new Bundle();
  396. if (v[i].Comments == null || v[i].Comments == "")
  397. {
  398. des.PutString("des", "没有备注");
  399. }
  400. else {
  401. des.PutString("des", v[i].Comments);
  402. }
  403. option.InvokeExtraInfo(des);
  404. mBaiduMap.AddOverlay(option);
  405. }
  406. }
  407. if (curPage > )
  408. {
  409. mapPreBtn.Visibility = ViewStates.Visible;
  410. }
  411. if (totalPage - > curPage)
  412. {
  413. mapNextBtn.Visibility = ViewStates.Visible;
  414. }
  415. if (totalPage > )
  416. {
  417. mapCurPage.Visibility = ViewStates.Visible;
  418. mapCurPage.Text = string.Format("{0}/{1}", curPage + , totalPage);
  419. }
  420. }
  421.  
  422. /// <summary>
  423. /// IRadarUploadInfoCallback要求实现的接口
  424. /// 实现上传callback,自动上传
  425. /// </summary>
  426. /// <returns></returns>
  427. public RadarUploadInfo OnUploadInfoCallback()
  428. {
  429. RadarUploadInfo info = new RadarUploadInfo();
  430. info.Comments = userComment;
  431. info.Pt = pt;
  432. Log.Debug("hjtest", "OnUploadInfoCallback");
  433. return info;
  434. }
  435.  
  436. #region 实现IRadarSearchListener接口
  437. public void OnGetClearInfoState(RadarSearchError p0)
  438. {
  439. var error = p0;
  440. if (error == RadarSearchError.RadarNoError)
  441. {
  442. Toast.MakeText(this, "清除位置成功", ToastLength.Long).Show();
  443. }
  444. else {
  445. Toast.MakeText(this, "清除位置失败", ToastLength.Long).Show();
  446. }
  447. }
  448.  
  449. public void OnGetNearbyInfoList(RadarNearbyResult p0, RadarSearchError p1)
  450. {
  451. RadarNearbyResult result = p0;
  452. RadarSearchError error = p1;
  453. if (error == RadarSearchError.RadarNoError)
  454. {
  455. Toast.MakeText(this, "查询周边成功", ToastLength.Long).Show();
  456. //获取成功
  457. listResult = result;
  458. curPage = result.PageIndex;
  459. totalPage = result.PageNum;
  460. //处理数据
  461. ParseResultToList(listResult);
  462. ParseResultToMap(listResult);
  463. clearRstBtn.Enabled = true;
  464. }
  465. else {
  466. //获取失败
  467. curPage = ;
  468. totalPage = ;
  469. Toast.MakeText(this, "查询周边失败", ToastLength.Long).Show();
  470. }
  471. }
  472.  
  473. public void OnGetUploadState(RadarSearchError p0)
  474. {
  475. RadarSearchError error = p0;
  476. if (error == RadarSearchError.RadarNoError)
  477. {
  478. //上传成功
  479. if (!uploadAuto)
  480. {
  481. Toast.MakeText(this, "单次上传位置成功", ToastLength.Long).Show();
  482. }
  483. }
  484. else {
  485. //上传失败
  486. if (!uploadAuto)
  487. {
  488. Toast.MakeText(this, "单次上传位置失败", ToastLength.Long).Show();
  489. }
  490. }
  491. }
  492. #endregion
  493.  
  494. protected override void OnPause()
  495. {
  496. mMapView.OnPause();
  497. base.OnPause();
  498. }
  499.  
  500. protected override void OnResume()
  501. {
  502. mMapView.OnResume();
  503. base.OnResume();
  504. mTabHost.TabWidget.GetChildAt().SetBackgroundColor(Color.ParseColor("#B0E2FF"));
  505. }
  506.  
  507. protected override void OnDestroy()
  508. {
  509. // 退出时销毁定位
  510. mLocClient.Stop();
  511. //释放周边雷达相关
  512. RadarSearchManager.Instance.RemoveNearbyInfoListener(this);
  513. RadarSearchManager.Instance.ClearUserInfo();
  514. RadarSearchManager.Instance.Destroy();
  515. //释放地图
  516. ff3.Recycle();
  517. mMapView.OnDestroy();
  518. mBaiduMap = null;
  519. base.OnDestroy();
  520. }
  521.  
  522. //定位SDK回调
  523. public void OnReceiveLocation(BDLocation arg0)
  524. {
  525. if (arg0 == null || mBaiduMap == null)
  526. return;
  527. pt = new LatLng(arg0.Latitude, arg0.Longitude);
  528. MyLocationData locData = new MyLocationData.Builder()
  529. .Accuracy(arg0.Radius)
  530. // 此处设置开发者获取到的方向信息,顺时针0-360
  531. .Direction().Latitude(arg0.Latitude)
  532. .Longitude(arg0.Longitude).Build();
  533. if (mBaiduMap != null)
  534. {
  535. mBaiduMap.SetMyLocationData(locData);
  536. }
  537. }
  538.  
  539. /// <summary>
  540. /// ViewPager适配器
  541. /// </summary>
  542. public class MyPagerAdapter : PagerAdapter
  543. {
  544. public IList<View> mListViews;
  545.  
  546. public MyPagerAdapter(IList<View> mListViews)
  547. {
  548. this.mListViews = mListViews;
  549. }
  550.  
  551. public override int Count
  552. {
  553. get
  554. {
  555. return mListViews.Count;
  556. }
  557. }
  558.  
  559. public override void DestroyItem(View container, int position, Java.Lang.Object objectValue)
  560. {
  561. ((ViewPager)container).RemoveView(mListViews[position]);
  562. base.DestroyItem(container, position, objectValue);
  563. }
  564.  
  565. public override Java.Lang.Object InstantiateItem(View container, int position)
  566. {
  567. ((ViewPager)container).AddView(mListViews[position], );
  568. return mListViews[position];
  569. }
  570.  
  571. public override bool IsViewFromObject(View view, Java.Lang.Object objectValue)
  572. {
  573. return view == objectValue;
  574. }
  575.  
  576. public override IParcelable SaveState()
  577. {
  578. return null;
  579. }
  580. }
  581.  
  582. /// <summary>
  583. /// 结果列表listview适配器
  584. /// </summary>
  585. private class RadarResultListAdapter : BaseAdapter
  586. {
  587. private Demo17Radar demo17Radar;
  588. public List<RadarNearbyInfo> list;
  589.  
  590. public RadarResultListAdapter(Demo17Radar radar, List<RadarNearbyInfo> res) : base()
  591. {
  592. demo17Radar = radar;
  593. list = res;
  594. }
  595.  
  596. public override int Count
  597. {
  598. get
  599. {
  600. if (list == null || (list != null && list.Count < ))
  601. {
  602. return ;
  603. }
  604. else
  605. {
  606. return list.Count;
  607. }
  608. }
  609. }
  610.  
  611. public override View GetView(int position, View convertView, ViewGroup parent)
  612. {
  613. convertView = View.Inflate(demo17Radar, Resource.Layout.demo_info_item, null);
  614. TextView title = convertView.FindViewById<TextView>(Resource.Id.title);
  615. TextView desc = convertView.FindViewById<TextView>(Resource.Id.desc);
  616. title.SetTextColor(Color.ParseColor("#0000FF"));
  617. desc.SetTextColor(Color.ParseColor("#0000FF"));
  618. if (list == null || list.Count == || position >= list.Count)
  619. {
  620. desc.Text = "";
  621. title.Text = "";
  622. }
  623. else
  624. {
  625. if (list[position].Comments == null || list[position].Comments == "")
  626. {
  627. desc.Text = string.Format("{0}米_没有备注", list[position].Distance);
  628. }
  629. else {
  630. desc.Text = string.Format("{0}米_{1}",
  631. list[position].Distance, list[position].Comments);
  632. }
  633. title.Text = list[position].UserID;
  634. }
  635. return convertView;
  636. }
  637.  
  638. public override Java.Lang.Object GetItem(int index)
  639. {
  640. if (list == null)
  641. {
  642. return new RadarNearbyInfo();
  643. }
  644. else {
  645. return list[index];
  646. }
  647. }
  648.  
  649. public override long GetItemId(int id)
  650. {
  651. return id;
  652. }
  653. }
  654.  
  655. public View ComposeLayout(string s, int i)
  656. {
  657. LinearLayout layout = new LinearLayout(this);
  658. layout.Orientation = Orientation.Vertical;
  659. ImageView iv = new ImageView(this);
  660. iv.SetImageResource(i);
  661. LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
  662. ViewGroup.LayoutParams.MatchParent,
  663. ViewGroup.LayoutParams.WrapContent);
  664. lp.SetMargins(, , , );
  665. layout.AddView(iv, lp);
  666.  
  667. TextView tv = new TextView(this);
  668. tv.Gravity = GravityFlags.Center;
  669. tv.SetSingleLine(true);
  670. tv.Text = s;
  671. tv.SetTextColor(Color.ParseColor("#0000FF"));
  672. tv.TextSize = ;
  673. layout.AddView(tv, new LinearLayout.LayoutParams(
  674. ViewGroup.LayoutParams.MatchParent,
  675. ViewGroup.LayoutParams.MatchParent));
  676. return layout;
  677. }
  678. }
  679. }

7、修改MainActivity.cs

在MainActivity.cs文件的demos字段定义中,去掉【示例17】下面的注释。

运行观察结果。

【Android】3.17 示例17--周边雷达功能的更多相关文章

  1. This Android SDK requires Android Developer Toolkit version 17.0.0 or above. Current version is 10.0.0.v201102162101-104271. Please update ADT to the latest version.

    win7/xp 下面安装Android虚拟机,更新SDK后,在Eclipse preference里指向android-sdk-windows时. 出现 : This Android SDK requ ...

  2. Android端IM应用中的@人功能实现:仿微博、QQ、微信,零入侵、高可扩展

    本文由“猫爸iYao”原创分享,感谢作者. 1.引言 最近有个需求:评论@人(没错,就是IM聊天或者微博APP里的@人功能),就像下图这样:   ▲ 微信群聊界面里的@人功能    ▲ QQ群聊界面里 ...

  3. Android实现小圆点显示未读功能

    代码地址如下:http://www.demodashi.com/demo/13541.html 前言 以前我们实现这个功能都是用 BadgeView.java,大体就是将这个java类复制到自己的项目 ...

  4. Android使用Fragment来实现ViewPager的功能(解决切换Fragment状态不保存)以及各个Fragment之间的通信

    以下内容为原创,转载请注明:http://www.cnblogs.com/tiantianbyconan/p/3364728.html 我前两天写过一篇博客<Android使用Fragment来 ...

  5. Android 摇一摇之双甩功能

    Android 摇一摇之双甩功能 最近做一个摇一摇的功能 网上相关代码很多 但是这次的需求有点奇葩 要求是摇两次才生效 看起来好像很简单 但真正要做遇到的问题还是很多 时间限制 机型灵敏性 摇动的方式 ...

  6. 运行所有sdk目录下的示例,查看它们的功能,方便以后查寻

    运行所有sdk目录下的示例,查看它们的功能,方便以后查寻

  7. SkylineGlobe Android 开发 面积计算示例代码

    SkylineGlobe Android 开发 面积计算示例代码: 如果之前熟悉SkylineGlobe桌面端的二次开发,看这些代码应该不难理解. package com.skyline.terrae ...

  8. Eclipse for android 实现代码自动提示智能提示功能

    Eclipse for android 实现代码自动提示智能提示功能,介绍 Eclipse for android 编辑器中实现两种主要文件 java 与 xml 代码自动提示功能,解决 eclips ...

  9. Android vcard使用示例,生成vcf文件

     Android vcard使用示例,生成vcf文件 我们备份手机联系人时,导出到SD卡时,会在SD卡中生成一个vcf文件,用于保存联系人姓名,手机号码. vCard 规范容许公开交换个人数据交换 ( ...

随机推荐

  1. Hibernate框架简介(二)基本使用增、删、改、查

    一.Hibernate框架简介 Hibernate是一个优秀的Java持久化层解决方案,是当今主流的对象-关系映射(ORM,ObjectRelationalMapping)工具 1.1.理解持久化 瞬 ...

  2. 基于apktool项目的android批量打包工具,多平台支持

    好久木有写博客了,今天有点兴致就写一下,献上一个没怎么用的批量打包工具,python实现的,虽然说现在android的批量打包有一个很好的工具可以使用gradle,这个灰常牛叉的工具和android ...

  3. codeforces Epic Game 题解

    Simon and Antisimon play a game. Initially each player receives one fixed positive integer that does ...

  4. Linux see 网卡当前流量

    linux see网卡的当前流量 sar –n DEV  1 2  命令后面1 2 意思是:每一秒钟取1次值,取2次. DEV显示网络接口信息 -n参数很有用,他有6个不同的开关:DEV | EDEV ...

  5. 〖Linux〗Shell脚本修改输出文字颜色

    Shell函数: echocolor(){ color=${} && shift case ${color} in black) echo -e "\e[0;30m${@}\ ...

  6. Adaptive Thresholding & Otsu’s Binarization

    Adaptive Thresholding Adaptive Method - It decides how thresholding value is calculated. cv2.ADAPTIV ...

  7. python之函数用法vars()

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法vars() #vars() #说明:返回对象object的属性和属性值的字典对象 ' ...

  8. python之函数用法file()

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法file() #file() #说明:file()内建函数它的功能等于open(),但 ...

  9. vs2017预览版下载

    vs2017预览版,没有限制的不过不能生成生产版本,集成最新的功能! 下载地址: https://www.visualstudio.com/zh-hans/vs/preview/

  10. HighCharts/Highstock使用小结,使用汉化及中文帮助文档

       此文档是本人在开发过程图形报表时使用HighCharts所遇到的问题及解决方案 .最后附上有HighCharts中文帮助文档 HighCharts  版本:Highcharts-3.0.1 Hi ...