最后,我决定使用TwoWayView库。
你可以从:https ://github.com/lucasr/twoway-view
在我的代码中,我做了以下主要更改:
在 xml 布局中添加了 TwoWayView:
<org.lucasr.twowayview.widget.TwoWayView
android:id="@+id/twvGrid"
android:background="@android:color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
style="@style/TwoWayView"
app:twowayview_layoutManager="SpannableGridLayoutManager"
app:twowayview_numColumns="3"
app:twowayview_numRows="3" />
在代码中,我做了以下更改:
private TwoWayView mTwvGrid;
.........
mTwvGrid = (TwoWayView) findViewById(R.id.twvGrid);
final Drawable divider = getResources().getDrawable(R.drawable.divider);
mTwvGrid.addItemDecoration(new DividerItemDecoration(divider));
mTwvGrid.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
RequestManager glideRequestManager = Glide.with(TimelineStoryActivity.this);
if (newState == RecyclerView.SCROLL_STATE_IDLE || newState == RecyclerView.SCROLL_STATE_SETTLING) {
glideRequestManager.resumeRequests();
} else {
glideRequestManager.pauseRequests();
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {}
});
.......
if (mAdapter == null) {
mAdapter = new TimelineStoryRecycleAdapter(this, mStory, mTwvGrid, this);
mTwvGrid.setAdapter(mAdapter);
} else {
mAdapter.setStory(mStory);
}
这是最终结果: