【发布时间】:2010-09-06 12:21:41
【问题描述】:
我有下面的屏幕,其中包含一些图像(每个可见页面 6 个)。上下滚动对我来说似乎很滞后。就像它再次渲染图像一样。向上滚动似乎比向下滚动更糟糕。
有人知道如何提高此类区域的性能以创建漂亮的平滑滚动吗?
更新:图片和文字都是从我的 SQLite 数据库中检索出来的。该列表是使用 SimpleCursorAdapter 创建的。
private class HistoryViewBinder implements SimpleCursorAdapter.ViewBinder
{
//private int wallpaperNumberIndex;
private int timeIndex;
private int categoryIndex;
private int imageIndex;
private java.text.DateFormat dateFormat;
private java.text.DateFormat timeFormat;
private Date d = new Date();
public HistoryViewBinder(Context context, Cursor cursor)
{
dateFormat = android.text.format.DateFormat.getDateFormat(context);
timeFormat = android.text.format.DateFormat.getTimeFormat(context);
//wallpaperNumberIndex = cursor.getColumnIndexOrThrow(HistoryDatabase.KEY_WALLPAPER_NUMBER);
timeIndex = cursor.getColumnIndexOrThrow(HistoryDatabase.KEY_TIME);
categoryIndex = cursor.getColumnIndexOrThrow(HistoryDatabase.KEY_CATEGORY);
imageIndex = cursor.getColumnIndexOrThrow(HistoryDatabase.KEY_IMAGE);
}
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex)
{
Log.d(TAG, "setViewValue");
if (view instanceof TextView)
{
Log.d(TAG, "TextView");
TextView tv = (TextView) view;
if (columnIndex == timeIndex)
{
Log.d(TAG, "timeIndex");
d.setTime(cursor.getLong(columnIndex));
tv.setText(timeFormat.format(d) + " " + dateFormat.format(d));
return true;
}
else if (columnIndex == categoryIndex)
{
Log.d(TAG, "categoryIndex");
tv.setText(cursor.getString(columnIndex));
return true;
}
}
else if (view instanceof ImageView)
{
Log.d(TAG, "ImageView");
ImageView iv = (ImageView) view;
if (columnIndex == imageIndex)
{
Log.d(TAG, "imageIndex");
byte[] image = cursor.getBlob(columnIndex);
Bitmap bitmapImage = BitmapFactory.decodeByteArray(image, 0, image.length);
iv.setImageBitmap(bitmapImage);
return true;
}
}
return false;
}
}
【问题讨论】:
-
如果您能发布创建单个列表项的 getView 方法的代码,我会很有帮助。
-
@Janusz 我不使用 getView。我使用 SimpleCursorAdapter 创建这个视图。
-
您能否发布 SimpleCursorAdapter 的创建,如果您正在扩展光标适配器的 bindView 方法?
-
@Janusz 我已经发布了 SimpleCursorAdapter 类。
标签: android performance android-listview