ListView的优化

1、如何优化listView或者如何优化gridView

2、如何优化android虚拟机

所有优化问题的思路:

1.时间换时间(延时加载)

2.空间换时间

使用缓存

public View getView(int position, View convertView, ViewGroup parent) {
        AppInfo info=appInfoList.get(position);
        //填充器方法是非常的消耗内存的,所以我们可以使用convertView,来进行优化
        //converView是历史的view对象,就是当拖动view的时候,那些消失的view的缓存
        //用回收掉的view对象来显示新生成的view,这样就可以极大的减少view对象的创建,达到优化的目的。
        View view;
        if(convertView==null){
            Log.i(TAG, "创建新的view对象");
             view=View.inflate(context, R.layout.software_item, null);
        }else{
            Log.i(TAG, "使用convertView对象");
            view=convertView;
        }
        TextView appName=(TextView) view.findViewById(R.id.appName);
        ImageView appImage=(ImageView) view.findViewById(R.id.appImage);
        appName.setText(info.getAppName());
        appImage.setImageDrawable(info.getIcon());
        return view;
        
        /*下面的代码是没有使用历史view缓存的(convertView)的
        View view=View.inflate(context, R.layout.software_item, null);
        TextView appName=(TextView) view.findViewById(R.id.appName);
        ImageView appImage=(ImageView) view.findViewById(R.id.appImage);
        appName.setText(info.getAppName());
        //System.out.println("nihao"+info.getAppName());
        appImage.setImageDrawable(info.getIcon());
        return view;*/
    }
原文地址:https://www.cnblogs.com/DASOU/p/4172707.html