0

我如何滚动与我的 tts 相关的视图(recyclerview),我查看了 onUtterance 但它似乎只有一个开始和停止监听器,所以我需要跳出框框思考,我给我的 tts 一个来自 Arraylist 之类的字符串这个

 ArrayList<String> list = new ArrayList<>();

    for (int i = 0; i < SpeakRecyclerGrid.recyclerView.getChildCount(); i++) 
      {
       list.add(((EditText) SpeakRecyclerGrid.recyclerView.getChildAt(i)).getText().toString());
      }

      speakWords(words);

我正在考虑将绳子切成几段,然后一次将一根绳子交给 TTS,然后一边移动一边移动视图。我已经为我的网格布局管理器提供了一个 int 列(称为列)的数量。数组列表在每个单词后添加一个逗号,所以我在想类似

  • 找到第 n 个/(列)逗号
  • 拆分字符串
  • 检查 tts 是否在说话并监听 onUtterance onDone 以传递新字符串
  • 读取字符串
  • 移动视图

并继续这样做,直到没有留下任何单词并为其余部分进行编码%我不确定如何做所有这些,所以如果有人想帮助感觉自由,(我想我正在查看 StringUtils 并使用 for 循环创建每个较小的字符串和将它们传递给 onUtteranceListener onDone 中的 tts,但我对 android 还是有点陌生​​),但主要是有人有更好的方法吗

4

1 回答 1

0

好的,这就是我目前所拥有的,但它可能需要一些工作,我仍然是一个业余爱好者,我已经根据屏幕的大小将字符串分成块,滚动屏幕的处理程序依赖于字母的数量每个分解的字符串,smoothscrolltoposition 也在滚动一个自定义布局管理器,它滚动得很慢我有一个问题,尽管在某些设备上计数单词的数组列表只会达到 20 不知道为什么但我会问,希望在我修复后更新这个所以这是我的说话和移动方法

public void speakAndMove(){

    final ArrayList<String> list = new ArrayList<>();

    SpeakGrid.recyclerView.getLayoutManager().scrollToPosition(0);

    for (int i = 0; i < SpeakRecyclerGrid.recyclerView.getChildCount(); i++) {
        list.add(((EditText) SpeakRecyclerGrid.recyclerView.getChildAt(i)).getText().toString());
    }

    Integer numOfWords = list.size();
    words = list.toString();
    Integer count = 0;
    Integer startPoint = 0;
    scrollPos = 0;
    final Integer speed = words.length() * 15;
    Integer leftOver = 0;
    final int columns = getResources().getInteger(R.integer.grid_columns);
    System.out.println(numOfWords);
    ArrayList<String> arrayList = new ArrayList<>();

    if (list.size() <= columns) {

        if (words.contains("[]")) {
            speakWords("");
        } else if (words.contains(", 's")) {
            formatString = words.replaceFirst(", 's", "'s");
            speakWords(formatString);
        } else if (words.contains(", ing")) {
            formatString = words.replaceFirst(", ing", "ing");
            speakWords(formatString);
        } else {
            speakWords(words);
        }
    }
    if (list.size()>=columns) {

        for (int i = 0; i < words.length(); i++) {

            if (words.charAt(i) == ',') {
                count++;
                if (count == columns) {

                    String ab = words.substring(startPoint, i + 1);
                    //speakWords(ab);
                    if (ab.contains(", 's")) {
                        formatString = ab.replaceFirst(", 's", "'s");
                        speakWords(formatString);
                    } else if (ab.contains(", ing")) {
                        formatString = ab.replaceFirst(", ing", "ing");
                        speakWords(formatString);
                    } else {
                        speakWords(ab);
                    }
                    startPoint = i + 1;
                    count = 0;
                    leftOver = words.length() - startPoint;
                }


                //SpeakGrid.recyclerView.getLayoutManager().scrollToPosition(scrollPos);
                System.out.println("main string"+" scroll " + scrollPos + " startpoint " + startPoint +" speed " + speed);
            }
        }
        if (leftOver > 0) {
            String ab2 = words.substring(startPoint, words.length());
            //speakWords(ab2);
            if (ab2.contains(", 's")) {
                formatString = ab2.replaceFirst(", 's", "'s");
                speakWords(formatString);
            } else if (ab2.contains(", ing")) {
                formatString = ab2.replaceFirst(", ing", "ing");
                speakWords(formatString);
            } else {
                speakWords(ab2);
            }
            //SpeakGrid.recyclerView.getLayoutManager().scrollToPosition(scrollPos);
            System.out.println("leftovers "+ leftOver + " scroll " + scrollPos + " startpoint " + startPoint +" count " + scrollPos);
            count = 0;
            //scrollPos = 0;
        }

    }

    final Handler h = new Handler();
    h.postDelayed(new Runnable() {
        public void run() {
            // This method will be executed once the timer is over
            // Start your app main activity

            scrollPos = scrollPos + columns;
            SpeakGrid.recyclerView.getLayoutManager().smoothScrollToPosition(SpeakGrid.recyclerView, null ,scrollPos);
            System.out.println("position "+ scrollPos + " speed " + speed + " list size " + list.size());
            if (scrollPos < list.size())
                h.postDelayed(this,speed);
            // close this activity
        }
    }, speed);


} 
于 2016-06-11T15:06:08.283 回答