我对让我的 GridView 正常工作有些麻烦。
当我滚动时,一些图像的滑动速度比其他图像快得多(它们不会留在他们的行中)。有时我也能够滚动到第一行之上!如果我跳过使用转换视图,我还没有看到问题。
---一些额外的背景--- 下面的 imageBufferLoader 对象扩展了我正在尝试开发的组件。它作为具有两个参数化窗口的对象(这次是图像)的现金。一个窗口用于最大对象的兑现(以避免内存问题)和一个用于最小对象加载的窗口(以便为滚动做准备)。我有发送给执行程序的可调用对象,一个用于填充数组的可调用对象,一个用于清理数组的调用对象。
也许我的问题与线程有关。
这是我的adater:
public class WebImageSearchResultAdapter extends BaseAdapter implements
PropertyChangeListener {
private ImageBufferLoader imageBufferLoader;
private Image image = new Image();
private Context context;
private Bitmap bitmapIC_Delete;
private static Handler handleUIEvents;
private LoggerAndroid logger;
private int lastPosRequest;
private RelativeLayout zeroView;
public WebImageSearchResultAdapter(Context context, Parameters parameters) {
this.context = context;
handleUIEvents = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
notifyDataSetChanged();
logger.LogD("Notify Data set Changed");
super.handleMessage(msg);
}
};
bitmapIC_Delete = BitmapFactory.decodeResource(context.getResources(),
R.drawable.ic_delete);
logger = new LoggerAndroid(
LoggerAndroid.isLoggingactivewebimagesearchresultadapter(),
"WebImageSearchResultAdapter", "");
Logger loggerImageBuffer = new LoggerAndroid(
LoggerAndroid.isLoggingactiveimagebufferloader(),
"ImageBuffer", "ImageBuffer");
Logger loggerImageDataBuffer = new LoggerAndroid(
LoggerAndroid.isLoggingactiveimagebufferloader(),
"ImageDataBuffer", "ImageDataBuffer");
imageBufferLoader = new ImageBufferLoader(loggerImageBuffer,
loggerImageDataBuffer, parameters, false, 50, 50, false, true, 50, 200);
imageBufferLoader.addChangeListener(this);
try {
imageBufferLoader.startService();
} catch (TimeoutException e) {
ExceptionHandler.getInstance(true).handleException(e);
}
}
public void setParameters(Parameters parameters) {
imageBufferLoader.setParameters(parameters);
zeroView = null;
}
public int getCount() {
// TODO Auto-generated method stub
return 1000;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
logger.LogD("ASK: " + position);
lastPosRequest = position;
RelativeLayout view2 = null;
ImageView imageView = null;
if (convertView == null) {
view2 = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.listimageitem, parent, false);
} else {
view2 = (RelativeLayout) convertView;
}
imageView = (ImageView) view2.findViewById(R.id.imageThumbnail);
if (position == 0 && zeroView != null) {
view2 = zeroView;
} else if (imageBufferLoader.isServiceRunning()
&& imageBufferLoader.isFillCleanRunning()) {
try {
if (imageBufferLoader.isDataAvailable(position)) {
image = imageBufferLoader.getData(position);
imageView.setImageBitmap(image.getThumbnailBitmap());
if(position == 0){
zeroView = view2;
}
logger.LogD("RET IMAGE for: " + position);
} else {
imageView.setImageBitmap(bitmapIC_Delete);
imageBufferLoader.loadData(position);
logger.LogD("RET: IC_DELETE for position " + position +"Request added to Queue");
}
} catch (Exception e) {
ExceptionHandler.getInstance(true).handleException(e);
imageBufferLoader.stopService();
imageView.setImageBitmap(bitmapIC_Delete);
logger.LogD("RET: IC_DELETE for position " + position +" EXCEPTION");
}
} else {
imageView.setImageBitmap(bitmapIC_Delete);
logger.LogD("RET: IC_DELETE for position " + position +" SERVICE NOT RUNNING TRY TO RESTART");
imageBufferLoader.start();
}
return view2;
}
public void propertyChange(PropertyChangeEvent event) {
String proptertyName = event.getPropertyName();
if (proptertyName.equals("Filling Ready")) {
handleUIEvents.sendMessage(new Message());
}
if (proptertyName.equals("BufferCleared")) {
if (imageBufferLoader.isServiceRunning()
&& imageBufferLoader.isFillCleanRunning()) {
imageBufferLoader.loadData(lastPosRequest);
}
}
}
}
这是我与 gridwiev 的片段
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<View
android:layout_width="0dp"
android:layout_height="fill_parent" />
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="300dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" >
</GridView>
<View
android:layout_width="0dp"
android:layout_height="fill_parent" />
</LinearLayout>
这是我在适配器中膨胀的布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="300dp" >
<ImageView
android:id="@+id/imageThumbnail"
android:layout_width="300dp"
android:layout_height="300dp"
/>
</RelativeLayout>