Android和ListView具有非常差和慢的滚动

时间:2012-05-22 12:07:46

标签: android performance listview

我有一个自定义列表视图。在这个列表中,我有15个项目。当我试图滚动时,滚动非常缓慢而且不平滑。

这是我的listView:

 <ListView
  android:id="@+id/AnnouncementsList"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_marginTop="25dp"
  android:cacheColorHint="#00000000"
  android:fastScrollEnabled="true"
  android:scrollingCache="true"
  android:smoothScrollbar="true" 
  android:layout_marginLeft="5dp"
  android:layout_marginRight="5dp"/>

这是我的列表适配器:

public class AnnouncementsListAdapter extends BaseAdapter {

private static ArrayList<NewsAnnouncements_Database> announcementsArrayList;

private LayoutInflater mInflater;

public AnnouncementsListAdapter(Context context, ArrayList<NewsAnnouncements_Database> searchResults) {
     announcementsArrayList = searchResults;
     mInflater = LayoutInflater.from(context);
 }


 public int getCount() {
  return announcementsArrayList.size();
 }


 public Object getItem(int position) {
  return announcementsArrayList.get(position);
 }


 public long getItemId(int position) {
  return position;
 }


 public View getView(int position, View convertView, ViewGroup parent) {
  ViewHolder holder;
  if (convertView == null) {     
       convertView = mInflater.inflate(R.layout.announcements_customisation, null);
       holder = new ViewHolder();
       holder.AnnouncementsTitle = (TextView) convertView.findViewById(R.id.AnnouncementsTitle);
       holder.AnnouncementsContent = (TextView) convertView.findViewById(R.id.AnnouncementsContent);
       convertView.setTag(holder);
  }
  else {
   holder = (ViewHolder) convertView.getTag();
  } 
  holder.AnnouncementsTitle.setText(Html.fromHtml(announcementsArrayList.get(position).getTitle()));
  holder.AnnouncementsContent.setText(Html.fromHtml(announcementsArrayList.get(position).getContent()));
  return convertView;
}

 static class ViewHolder {
  TextView AnnouncementsTitle;
  TextView AnnouncementsContent;
 }

}

1 个答案:

答案 0 :(得分:1)

尝试在XML布局中删除cacheColorHint属性。