ViewPager没有快速响应

时间:2016-07-04 14:23:37

标签: java android android-fragments android-viewpager

在使用ViewPager时,我注意到它不会很快响应,这意味着当切换片段时,它会以一种迟滞的方式减慢速度。 是否有人知道此代码如何导致此问题?

public class List_adapter : BaseAdapter<Element>
{
    public List<Element> _list; 
    FragmentOne _context;


    public List_adapter(FragmentOne context, List<Element> list) 
    {                                                 
    super(context, list);                     
        _list = list;
        _context = context;
    }
    @Override
    public int getCount() 
    {
        return _list.size();
    }
    @Override
    public Object getItem(int position) 
    {
        return _list.get(position);
    }
    @Override
    public long getItemId(int position) 
    {
        return getItem(position).hashCode();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        LayoutInflater inflater = (LayoutInflater)getActivity().getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.row, parent, false); 
        Element item = getItem(position);
        TextView lbl = (TextView)view.findViewById(R.id.label);
        TextView prop = (TextView)view.findViewById(R.id.Prop);
        lbl.setText(item.getlabel()); 
        prop.setText(item.getprop()); 
        return view; 
    }


}

1 个答案:

答案 0 :(得分:1)

  1. 使用ViewHolder pattern进行流畅的列表滚动
  2. ViewPager
  3. 中显示视图之前,先实施Offscreen page limit初始化视图