我有一個回收站視圖,它正在使用通用圖像加載程序進行填充。Recycler查看Scroll上的隨機圖像
@Override
public MasonryView onCreateViewHolder(ViewGroup parent, int viewType) {
View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.grid_item, parent, false);
MasonryView masonryView = new MasonryView(layoutView);
//layoutView.setOnClickListener(new MyOnClickListener());
//imageLoader.destroy();
imageLoader.init(ImageLoaderConfiguration.createDefault(context));
options = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.resetViewBeforeLoading(true)
.cacheOnDisk(true)
.considerExifParams(false)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
return masonryView;
}
@Override
public void onBindViewHolder(final MasonryView holder, int position) {
imageLoader
.displayImage(IMAGE_URLS[position], holder.imageView, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
holder.donut_progress.setVisibility(View.VISIBLE);
holder.donut_progress.setProgress(0);
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
holder.onLoadImage.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
holder.onLoadImage.setVisibility(View.GONE);
holder.donut_progress.setVisibility(View.GONE);
}
}, new ImageLoadingProgressListener() {
@Override
public void onProgressUpdate(String imageUri, View view, int current, int total) {
holder.donut_progress.setProgress(Math.round(100.0f * current/total));
}
});
}
正如您所看到的imageloader和DisplayOptions在CreateView中定義的。
圖像顯示成功,但在滾動圖像時正在洗牌。
以下是我對custom_recycler_grid_item XML
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:orientation="vertical">
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"/>
!-- android:scaleType="centerCrop" --!
<ImageView
android:id="@+id/onLoadImage"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/camera_cross"
android:layout_marginLeft="50dp"
android:layout_marginTop="50dp"
android:visibility="gone"/>
<progressIndicators.DonutProgress
android:layout_marginLeft="50dp"
android:layout_marginTop="50dp"
android:id="@+id/donut_progress"
android:layout_width="50dp"
android:layout_height="50dp"
custom:donut_unfinished_stroke_width="1dp"
custom:donut_finished_stroke_width="1dp"
custom:donut_progress="50"/>
</FrameLayout>
我的主要碎片,具有recyclerView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/masonry_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.1"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout>
不過,我還設置 adapter.setHasStableIds(真);
安置自己的XML代碼 – vinoth12594
好吧進出口張貼我custom_item.xml –
您添加了android:滾動條=「垂直」在你的回收站視圖 – vinoth12594