简体   繁体   English

我怎样才能平滑listView滚动?

[英]How can i smooth listView scrolling?

I am writing a media player application using Media extractor API. 我正在使用Media Extractor API编写媒体播放器应用程序。 So my decoder decodes the data and shows content on surface. 因此,我的解码器解码数据并在表面显示内容。 This is working fine. 一切正常。 I have one list view. 我有一个列表视图。 When i scroll this listview, it showing effect on decoder thread. 当我滚动此列表视图时,它在解码器线程上显示效果。 So i am getting some disturbance. 所以我受到一些干扰。 How can i resolve that. 我该如何解决。 Is there any way to run my listView Adapter( getView() method) on separate thread? 有什么办法可以在单独的线程上运行我的listView Adapter(getView()方法)? I saw this link. 我看到了这个链接。 It may not helpful to me. 这可能对我没有帮助。 http://developer.android.com/training/improving-layouts/smooth-scrolling.html Because My list item contain only one textView. http://developer.android.com/training/improving-layouts/smooth-scrolling.html因为我的列表项仅包含一个textView。

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView txt_Effects;
        ImageView proImage;
        if(convertView == null){
            LayoutInflater inflater= (LayoutInflater)context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView= inflater.inflate(R.layout.row_listview, null);
            txt_Effects= (TextView)convertView.findViewById(R.id.txt_row);
            proImage= (ImageView)convertView.findViewById(R.id.proImage_row);
        }
        else{
            txt_Effects= (TextView)convertView.findViewById(R.id.txt_row);
            proImage= (ImageView)convertView.findViewById(R.id.proImage_row);
        }

        txt_Effects.setText(data[position]);
        txt_Effects.setTextColor(Color.WHITE);
        proImage.setVisibility(View.GONE);

        if(position == previousSelectionIndex){
            txt_Effects.setTextColor(Color.MAGENTA);
            prevSelectedTextView= txt_Effects;
        }

        if(position>= startProIndex && position <= endProIndex){
            proImage.setVisibility(View.VISIBLE);
        }



        return convertView;
    }

You should perform all "heavy" operations outside of getView() method. 您应该在getView()方法之外执行所有“繁重的”操作。 Consider using AsyncTask or ThreadPool for doing your "decoding" and then update your ListView in the UI thread. 考虑使用AsyncTask或ThreadPool进行“解码”,然后在UI线程中更新ListView。

You may want to use the ViewHolder pattern to improved the performance of loading your list items. 您可能需要使用ViewHolder模式来提高加载列表项的性能。 Refer the following: 请参考以下内容:

Android ViewHolder Pattern Example Android ViewHolder模式示例

Holder Pattern 持有人模式

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM