0

我正在使用 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);
   }

我已经尝试以编程方式设置图像视图和查看器的宽度,但没有运气。感谢您提前提出建议或任何帮助。

4

1 回答 1

0

最后我改为使用 Asymmentric recyclerview 库。这个库中没有这样的问题。请按照以下链接。

https://github.com/felipecsl/AsymmetricGridView?utm_source=android-arsenal.com&utm_medium=referral&utm_campaign=1186

于 2018-05-02T14:22:38.867 回答