android耗时操作也是操作UI的,如何处理
習慣沉默
習慣沉默 2017-05-24 11:38:10
0
1
753

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));
}

//先是通过网络请求获取比较大量的经纬度点,然后我会在地图上根据点绘制成线。现在关键问题就是线在绘制过程中会比较耗时,页面会卡住(这样并不好)。因为数据量会大一点,但关键子线程的画 这个线又画不出来,在UI线程又会卡死。求助....

ps:试过在子线程中用runonuithread 去操作 中间的 addPolyLine ,但也不行。

这个方法在请求完数据后就直接执行了。
習慣沉默
習慣沉默

全部回复(1)
某草草

先在子线程画,然后通过handler在主线程刷新界面。
你要用rxjava的话实现就很方便了

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!