private void addPolylineInPlayGround() {
List<Integer> colorList = new ArrayList<Integer>();
List<BitmapDescriptor> bitmapDescriptors = new ArrayList<BitmapDescriptor>();
int[] colors = new int[]{Color.argb(255, 0, 255, 0), Color.argb(255, 255, 255, 0), Color.argb(255, 255, 0, 0)};
//用一个数组来存放纹理
List<BitmapDescriptor> textureList = new ArrayList<BitmapDescriptor>();
textureList.add(BitmapDescriptorFactory.fromResource(R.drawable.custtexture));
List<Integer> texIndexList = new ArrayList<Integer>();
texIndexList.add(0);//对应上面的第0个纹理
texIndexList.add(1);
texIndexList.add(2);
Random random = new Random();
for (int i = 0; i < latLngs.size(); i++) {
colorList.add(colors[random.nextInt(3)]);
bitmapDescriptors.add(textureList.get(0));
}
mPolyline = mAMap.addPolyline(new PolylineOptions().setCustomTexture(BitmapDescriptorFactory.fromResource(R.drawable.custtexture)) //setCustomTextureList(bitmapDescriptors)
.setCustomTextureIndex(texIndexList)
.addAll(latLngs)
.useGradient(true)
.width(18));
dismissLoading();
LatLngBounds bounds = new LatLngBounds(latLngs.get(0), latLngs.get(latLngs.size() - 2));
mAMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 200));
}
//First, obtain a relatively large number of latitude and longitude points through network requests, and then I will draw lines based on the points on the map. The key problem now is that the line drawing process will be more time-consuming and the page will get stuck (which is not good). Because the amount of data will be larger, but the line drawn by the key sub-thread cannot be drawn, and the UI thread will get stuck again. Help....
ps: I tried using runonuithread in the child thread to operate the middle addPolyLine, but it didn't work either.
这个方法在请求完数据后就直接执行了。
某草草2017-05-24 11:40:10
First draw in the sub-thread, and then refresh the interface in the main thread through the handler.
If you want to use rxjava, it will be very convenient