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

private void addPolylineInPlayGround() {

List colorList = new ArrayList(); List bitmapDescriptors = new ArrayList(); int[] colors = new int[]{Color.argb(255, 0, 255, 0), Color.argb(255, 255, 255, 0), Color.argb(255, 255, 0, 0)}; //用一个数组来存放纹理 List textureList = new ArrayList(); textureList.add(BitmapDescriptorFactory.fromResource(R.drawable.custtexture)); List texIndexList = new ArrayList(); 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學習者快速成長!