最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

RecyclerChart動態(tài)屬性圖標聯(lián)動數(shù)據(jù)動態(tài)加載詳解

 更新時間:2023年03月02日 08:55:36   作者:cxy107750  
這篇文章主要為大家介紹了RecyclerChart動態(tài)屬性圖標聯(lián)動數(shù)據(jù)動態(tài)加載詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

正文

本章節(jié)繼上一章節(jié)中相關(guān)的動態(tài)屬性作介紹,主要講述三個功能實現(xiàn)點,第一個是上下圖表聯(lián)動問題,類似于股票軟件K線上面的Candle圖跟下邊的MACD之類的圖表聯(lián)動的實現(xiàn);第二點是左右滑動,觸邊時數(shù)據(jù)動態(tài)加載的實現(xiàn);第三點當滑動Fling結(jié)束后,顯示數(shù)據(jù)跨了日、周、月視圖的一個周期時,數(shù)據(jù)回溯回彈的一個效果,之前IPhone的健康A(chǔ)PP實現(xiàn)了類似的效果,最近新的好像已經(jīng)去除了該效果。

下面的這個能量的圖表gif 能夠較好地看出聯(lián)動跟回溯的過程:

圖表聯(lián)動

類似于股票的K線跟底部成交量Barchat圖表,這里也是上下兩個Chart圖表,筆者在寫到這里的時候,突然間有個大膽的想法,就是完全可以在一個Chart里去繪制上下兩部分的數(shù)據(jù)展現(xiàn),這樣的話也不會存在兩個圖表聯(lián)動的問題,同時可能會因為少了一個Chart,性能更好。

好了,這里先講目前的實現(xiàn)方式。MPAndroidChart中的兩個上下兩個圖表也可以實現(xiàn)連動的方式實現(xiàn),通過OnChartGestureListener接口實現(xiàn)。因為RecyclerChart是基于Recyclerview 實現(xiàn)的,所以其實只需實現(xiàn)兩個Recylcerview的聯(lián)動即可。

如下在recyclerBarChart 的滑動監(jiān)聽中 同步處理recyclerLineChart的滑動,同樣包括回溯的滑動。

recyclerBarChart.addOnScrollListener(new RecyclerView.OnScrollListener() {
  private boolean isRightScrollInner;
  @Override
  public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);
    if (newState == RecyclerView.SCROLL_STATE_IDLE) {
      ....
      //回溯
      if (mBarChartAttrs.enableScrollToScale) {
        int scrollToByDx = ChartComputeUtil.computeScrollByXOffset(recyclerView, displayNumber, getXAxisType());
        recyclerView.scrollBy(scrollToByDx, 0);
        recyclerLineChart.scrollBy(scrollToByDx, 0);
      }
      .....
    }
  }
  @Override
  public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    //判斷左滑,右滑時,ScrollView的位置不一樣。
    isRightScrollInner = dx < 0;
    if (recyclerBarChart.getScrollState() != RecyclerView.SCROLL_STATE_IDLE) {
      mItemGestureListener.resetSelectedBarEntry();//清除recyclerLineChart的長按。
      recyclerLineChart.scrollBy(dx, dy);
    }
  }
});

同樣的,在線性表 recyclerLineChart 的滑動監(jiān)聽里需要同步處理recyclerBarChart的滑動,代碼類似。

數(shù)據(jù)動態(tài)加載

其實類似于分頁加載數(shù)據(jù),跟縱向vertical加載類似,這里是橫向horizontal處理的,同樣在上面的監(jiān)聽的Listener里面處理 當條件 !

recyclerView.canScrollHorizontally(-1) 左滑不動,加載數(shù)據(jù)到左邊,這里LayoutManager因為 reverse的,所以是 DataList.addAll(list);

當!recyclerView.canScrollHorizontally(1) 右滑不動是,DataList.addAll(0, list)

@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
  super.onScrollStateChanged(recyclerView, newState);
  if (newState == RecyclerView.SCROLL_STATE_IDLE) {
    //加載更多
    if (!recyclerView.canScrollHorizontally(-1) && isRightScrollInner) {//左滑不動
      loadData(updateUI(start))
    } else if (!recyclerView.canScrollHorizontally(1)) {//右滑不動
      loadData(updateUI(end))
    }
  }
}

回溯

這里先介紹一下實現(xiàn)方案:筆者在構(gòu)建Entry的時候埋了一個type的鉤子,當Entry屬于日周月視圖的邊界,比如日視圖的0點,周視圖的周一,月視圖的1號,通常情況下是這個Item的左邊界;但是當RTL時需要特殊處理。

第二,當停下來的時候,遍歷當前屏幕顯示的Items時,當不對齊的時候,這里必定存在一個上述提到的特殊邊界的Item,計算它到Chart邊界的(不包含XAis)的距離,存到一個DistanceCompare的對象中。

第三, 在RecyclerView松手Fling停止的時候,計算上面的DistanceCompare對象中的,distanceLeft、distanceRight; 根據(jù) isNearLeft() 去判斷是向左,還是向右回彈,isNearLeft() true 向左,否則向右。

//月線靠近左邊
public boolean isNearLeft(){
    return distanceLeft < distanceRight;
}
//計算 DistanceCompare 
private static <T extends RecyclerBarEntry> DistanceCompare findDisplayFirstTypePosition(RecyclerView recyclerView, int displayNumbers) {
  LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
  DistanceCompare distanceCompare = new DistanceCompare(0, 0);
  BaseBarChartAdapter adapter = (BaseBarChartAdapter) recyclerView.getAdapter();
  if (null == manager || null == adapter) {
    return distanceCompare;
  }
  List<T> entries = adapter.getEntries();
  int firstVisibleItemPosition = manager.findFirstVisibleItemPosition();
  int position = firstVisibleItemPosition; //從右邊的第一個View開始找
  int parentRight = recyclerView.getWidth() - recyclerView.getPaddingRight();
  int parentLeft = recyclerView.getPaddingLeft();
  for (int i = 0; i < displayNumbers; i++) {
    if (i > 0) {
      position++;
    }
    if (position >= 0 && position < entries.size()) {
      T barEntry = entries.get(position);
      if (barEntry.type == RecyclerBarEntry.TYPE_XAXIS_FIRST || barEntry.type == RecyclerBarEntry.TYPE_XAXIS_SPECIAL) {
        distanceCompare.position = position;
        View positionView = manager.findViewByPosition(position);
        if (null != positionView){
          int viewLeft = positionView.getLeft();
          int viewRight = positionView.getRight();
          distanceCompare.distanceRight = parentRight - viewRight;
          distanceCompare.distanceLeft = viewLeft - parentLeft;
        }
        distanceCompare.setBarEntry(barEntry);
        break;
      }
    }
  }
  return distanceCompare;
}

根據(jù) distanceCompare 計算 scrollByXOffset:簡單的數(shù)學(xué)計算,不過需要仔細。

public static <T extends RecyclerBarEntry> int computeScrollByXOffset(RecyclerView recyclerView, int displayNumbers, int type) {
  DistanceCompare distanceCompare = findDisplayFirstTypePosition(recyclerView, displayNumbers);
  LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
  BaseBarChartAdapter adapter = (BaseBarChartAdapter) recyclerView.getAdapter();
  if (null == adapter) {
  return 0;
  }
  List<T> entries = adapter.getEntries();
  int positionCompare = distanceCompare.position;
  //T entry = entries.get(positionCompare);
  View compareView = manager.findViewByPosition(positionCompare);
  if (null == compareView) {
  return 0;
  }
  int compareViewRight = compareView.getRight();
  int compareViewLeft = compareView.getLeft();
  int childWidth = compareView.getWidth();
  int parentLeft = recyclerView.getPaddingLeft();
  int parentRight = recyclerView.getWidth() - recyclerView.getPaddingRight();
  int scrollByXOffset;
  if (distanceCompare.isNearLeft()) {
  //靠近左邊,content左移,recyclerView右移,取正。
  //情況 1.
  int distance = AppUtils.isRTLDirection() ? compareViewLeft - parentLeft 
    : compareViewRight - parentLeft;//原始調(diào)整距離
  if (positionCompare < displayNumbers + 1) {
    //防止 positionCompare過大,計算firstViewRight時,int越界
  int firstViewRight = compareViewRight + positionCompare * childWidth;
  int distanceRightBoundary = Math.abs(firstViewRight - parentRight);//右邊界
  if (distanceRightBoundary < distance) { //content左移不夠,頂?shù)筋^,用distanceRightBoundary
  distance = distanceRightBoundary;
  }
  }
  scrollByXOffset = distance;
  } else {//靠近右邊,content右移,recyclerView左移,取負。
  int distance = AppUtils.isRTLDirection()?parentRight - compareViewLeft : 
    parentRight - compareViewRight;//原始調(diào)整距離
  if (entries.size() - positionCompare < displayNumbers) {
  //這個值會為負的。
  int lastViewLeft = compareViewLeft - (entries.size() - 1 - positionCompare) * childWidth;
  int distanceLeftBoundary = Math.abs(parentLeft - lastViewLeft);
    //右邊 - 左邊,因為 lastViewLeft是負值,實際上是兩值相加。
  if (distanceLeftBoundary < distance) {//content右移不夠,頂?shù)筋^,distanceLeftBoundary
  distance = distanceLeftBoundary;
  }
  }
  //記得取負, scrollBy的話f
  scrollByXOffset = distance - 2 * distance;
  }
  return scrollByXOffset;
}

最終也在onScrollStateChanged 實現(xiàn)回溯:

@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
  super.onScrollStateChanged(recyclerView, newState);
  if (newState == RecyclerView.SCROLL_STATE_IDLE) {
    .....
    //回溯
    if (mBarChartAttrs.enableScrollToScale) {
      int scrollToByDx = ChartComputeUtil.computeScrollByXOffset(
        recyclerView, displayNumber, getXAxisType());
      recyclerView.scrollBy(scrollToByDx, 0);
      recyclerLineChart.scrollBy(scrollToByDx, 0);
    }
    ......
  }
}

至此,RecyclerChart相關(guān)的動態(tài)屬性相關(guān)介紹完了,另外比如回溯完后,YAXis的變化等。

以上就是RecyclerChart動態(tài)屬性圖標聯(lián)動數(shù)據(jù)動態(tài)加載詳解的詳細內(nèi)容,更多關(guān)于RecyclerChart動態(tài)屬性的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • @Configuration保證@Bean單例語義方法介紹

    @Configuration保證@Bean單例語義方法介紹

    這篇文章主要介紹了SpringBoot中的@Configuration與@Bean注解,在進行項目編寫前,我們還需要知道一個東西,就是SpringBoot對我們的SpringMVC還做了哪些配置,包括如何擴展,如何定制,只有把這些都搞清楚了,我們在之后使用才會更加得心應(yīng)手
    2023-01-01
  • 異步線程traceId如何實現(xiàn)傳遞

    異步線程traceId如何實現(xiàn)傳遞

    文章介紹了如何在異步請求中傳遞traceId,通過重寫ThreadPoolTaskExecutor的方法和實現(xiàn)TaskDecorator接口來增強線程池,確保異步線程間的traceId同步
    2025-02-02
  • java中如何判斷JSONObject是否存在某個Key

    java中如何判斷JSONObject是否存在某個Key

    這篇文章主要介紹了java中如何判斷JSONObject是否存在某個Key,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • Java 字符串反轉(zhuǎn)實現(xiàn)代碼

    Java 字符串反轉(zhuǎn)實現(xiàn)代碼

    這篇文章主要介紹了 Java 字符串反轉(zhuǎn)實現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • spring cloud gateway集成hystrix全局斷路器操作

    spring cloud gateway集成hystrix全局斷路器操作

    這篇文章主要介紹了spring cloud gateway集成hystrix全局斷路器操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • springboot中swagger、異步/定時/郵件任務(wù)的問題

    springboot中swagger、異步/定時/郵件任務(wù)的問題

    這篇文章主要介紹了springboot中swagger、異步/定時/郵件任務(wù)的問題,本文給大家介紹的非常詳細,對大家的學(xué)習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-07-07
  • 新手了解java IO基礎(chǔ)知識

    新手了解java IO基礎(chǔ)知識

    這篇文章主要介紹了java 基礎(chǔ)知識之IO總結(jié)的相關(guān)資料,Java中的I/O分為兩種類型,一種是順序讀取,一種是隨機讀取,需要的朋友可以參考下,希望對你有幫助
    2021-07-07
  • Java項目--家庭收支記錄程序

    Java項目--家庭收支記錄程序

    本文主要介紹Java基礎(chǔ)階段的一個小項目——家庭收支記錄程序(附完整源代碼),本項目所用到的主要知識點:基本語法、數(shù)組和方法。本項目并不難,主要是對Java初學(xué)者的基礎(chǔ)綜合運用的訓(xùn)練及檢驗
    2021-07-07
  • java優(yōu)化hibernate性能的幾點建議

    java優(yōu)化hibernate性能的幾點建議

    以上是在進行struts+hibernate+spring進行項目開發(fā)中,對hibernate性能優(yōu)化的幾點心得。
    2008-10-10
  • idea創(chuàng)建properties文件,解決亂碼問題

    idea創(chuàng)建properties文件,解決亂碼問題

    這篇文章主要介紹了idea創(chuàng)建properties文件,解決亂碼問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07

最新評論

诏安县| 连江县| 林西县| 大邑县| 梓潼县| 昌邑市| 木里| 新竹市| 洪雅县| 奎屯市| 防城港市| 通化县| 龙口市| 钦州市| 南部县| 清原| 蒙阴县| 南郑县| 侯马市| 常宁市| 彝良县| 射洪县| 石台县| 高淳县| 和静县| 天峻县| 龙川县| 开江县| 宁阳县| 沅陵县| 正定县| 上饶县| 阳城县| 阿勒泰市| 天气| 屏东县| 五莲县| 镇坪县| 登封市| 东乌| 鞍山市|