我正在使用TwoWayView
https://github.com/lucasr/twoway-view
它正在工作,但是当从服务器加载图像时滚动到顶部时有时会出现空白。
我的屏幕xml:
<package.TwoWayView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/listTwoWay"
style="@style/TwoWayView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:twowayview_layoutManager="StaggeredGridLayoutManager"
app:twowayview_numColumns="2"
app:twowayview_numRows="2" />
我的行布局有固定高度和宽度
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="300dp"
android:layout_height="300dp"
android:background="@color/color_white_gray">
<ImageView
android:id="@+id/imgItemGrid"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:scaleType="fitXY"
android:src="@drawable/artist_expand_bg1" />
</RelativeLayout>
和我的适配器onbind如下所示
@Override
public void onBindViewHolder(final SimpleViewHolder holder, final int position) {
final View itemView = holder.itemView;
//set imageview
Glide.with(mContext)
.load(dataList.get(position).getImage())
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
holder.progressBar.setVisibility(View.GONE);
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
holder.progressBar.setVisibility(View.GONE);
return false;
}
})
.into(holder.imgItemGrid);
final int dimenId;
final int span;
if (position == 0) {
dimenId = R.dimen.staggered_child_large;
span = 2;
} else {
dimenId = R.dimen.staggered_child_large;
span = 2;
}
final int size = mContext.getResources().getDimensionPixelSize(dimenId);
final StaggeredGridLayoutManager.LayoutParams lp =
(StaggeredGridLayoutManager.LayoutParams) itemView.getLayoutParams();
lp.span = span;
lp.height = size;
itemView.setLayoutParams(lp);
}
我已尝试以编程方式设置imageview和viewholder的宽度,但没有运气。 感谢您提出建议或提供任何帮助。
答案 0 :(得分:0)
最后我改为Asymmentric recyclerview库。这个图书馆里没有这样的问题。请点击以下链接。