移动搜索栏不流畅

移动搜索栏不流畅

本文介绍了移动搜索栏不流畅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Seekbar 并且我实现了如下源代码:

 seekProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {@覆盖public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {调整组合(进度);}@覆盖公共无效 onStartTrackingTouch(SeekBar seekBar) {}@覆盖公共无效 onStopTrackingTouch(SeekBar seekBar) {}});

因为函数:adjustCombination(progress) 需要 0.2s 来完成执行,所以当我移动 Seekbar 时,它不流畅.那么我该如何解决这个问题呢?

解决方案

你可以像这样使用 AsyncTask 来执行你的后台任务,

seekProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {@覆盖public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {新的 getData().execute(progress);}@覆盖公共无效 onStartTrackingTouch(SeekBar seekBar) {}@覆盖公共无效 onStopTrackingTouch(SeekBar seekBar) {}});

现在,您必须定义 getData() 来执行和传递您需要的任何参数.在你的情况下,我们必须通过进度,

private class getData extends AsyncTask{@覆盖protected void onPreExecute() {super.onPreExecute();}@覆盖protected String doInBackground(String... progress) {//用 String "progress" 执行你想要的操作字符串值 = "你好" + 进度;返回值;}@覆盖protected void onPostExecute(String progressResult) {//在这个线程中做任何你想做的事//textview.setText(progressResult)super.onPostExecute(progressResult);}}

因此,PreExecute 方法将在后台执行任何任务之前执行,然后您的 doInBackground 方法将被调用,并且您将在调用 doInBackground onPostExecute 方法后获得传入此方法的参数,该方法将接收从 doInBackground 方法返回的结果.我希望你能明白.

I have Seekbar and I implemented source code as below:

        seekProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            adjustCombination(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

Because function: adjustCombination(progress) need 0,2s to finish executing so when I move Seekbar, it's not smooth. So how I can fix the issue ?

解决方案

you can perform your background task using AsyncTask like this,

seekProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            new getData().execute(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

now, you have to define getData() to perform and pass the arguments whichever you required. in you case, we have to pass the progress,

private class getData extends AsyncTask<String, Void, String> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected String doInBackground(String... progress) {
        // perform operation you want with String "progress"
        String value = "hello" + progress;
        return value;
    }

    @Override
    protected void onPostExecute(String progressResult) {
        // do whatever you want in this thread like
        // textview.setText(progressResult)
        super.onPostExecute(progressResult);
    }
}

这篇关于移动搜索栏不流畅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 07:03