ListView性能与2,000项 - laggy

时间:2015-11-11 17:08:12

标签: android performance listview android-listview

我有ListView,有2,000件物品。当我向下滚动 - 第一个appx。 300项物品快速滚动,然后开始滞后。奇怪的是,在列表加载后,我得到四个GC freed (some memory),当我快速滚动时,我得到更多:

Background partial concurrent mark sweep GC freed 103571(3MB) AllocSpace objects, 4(1398KB) LOS objects, 39% free, 15MB/26MB, paused 12.591ms total 122.076ms

我的ListView有:

android:animationCache="false"
android:scrollingCache="false"

代码:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View rowView = convertView;

    if (convertView == null) {
        int type = getItemViewType(position);
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        ViewHolder holder;
        switch (type) {
            case TYPE_ITEM:
                rowView = inflater.inflate(R.layout.row_view_new, null);
                holder = new ViewHolder();
                holder.tvBrewery =(TextView) rowView.findViewById(R.id.browar);
                holder.tvTitle = (TextView) rowView.findViewById(R.id.row_title);
                //holder.tvStyle = (TextView) convertView.findViewById(R.id.gatunek);
                rowView.setTag(holder);
                break;
            case TYPE_SECTION:

                rowView = inflater.inflate(R.layout.section_row_view, null);
                holder = new ViewHolder();
                holder.tvTitle = (TextView) rowView.findViewById(R.id.row_title);
                rowView.setTag(holder);
                break;
        }
    }
    ViewHolder fHolder = (ViewHolder) rowView.getTag();
    if(mListItems.get(position).getBeerName() != null)
        fHolder.tvTitle.setText(mListItems.get(position).getBeerName());

    if(mListItems.get(position).getBrewery() != null)
        fHolder.tvBrewery.setText(mListItems.get(position).getBrewery());

    return rowView;
}

正如您所见,布局层次结构很简单 - 一个TextView中有三个RelativeLayout

1 个答案:

答案 0 :(得分:0)

我看到你有两种类型的行,你是否尝试过这些功能:

getViewTypeCount() - 此方法返回信息列表中有多少行类型

getItemViewType(int position) - 根据位置

返回您应使用的布局类型的信息

然后只有在布局为空时才会对布局进行膨胀,并使用getItemViewType确定类型。国际海事组织将减少迟缓。