有没有一种方法来共享多个嵌套RecyclerViews之间的相同的布局管理 [英] Is there a way to share a same LayoutManager between multiple nested RecyclerViews

查看:278
本文介绍了有没有一种方法来共享多个嵌套RecyclerViews之间的相同的布局管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的表示游戏列表,每场比赛的ItemView控件中的应用程序,我也有一个视频列表将显示。 preVIEW和结构如下。

I'm developing an application that showing a game list, inside every game's itemView, i also have a video list to be showing. preview and structure are following.

我部署RecyclerView作为窗口根视图,然后在视频,我用的网格式RecyclerView显示,所以在这里我们得到了一个嵌套RecyclerView结构。

I deploy a RecyclerView as the window root view, and then for the videos, i used grid-style RecyclerView to display, so here we got a nested RecyclerView structure.

但有麻烦了,因为影片的数量是游戏之间的矛盾,我不想的视频列表的RecyclerView能够被滚动,所以最好的办法就是让观的高度伸展动态取决于它有多少行有。我听到了一个令人失望的结论说,没有办法从互联网上做到这一点。那是真的吗?任何其他能这样做呢?

But there is trouble because the number of videos is inconsistent between games, i don't want the RecyclerView of video list able to being scroll, so the best way is make the View's height stretch dynamically depends on how much rows it have. I heard a disappointing conclusion said there is no a way to accomplish this from internet. Is that really? any alternative can doing this?

到目前为止,关于这个问题,我没有想法去解决它,所以我手动更改RecyclerView的高度作为一种临时解决方案。

So far about this question, i haven't idea to solve it, so i change the RecyclerView's height manually as a temporary solution.

videoGridRecyclerView.getLayoutParams().height = rowCount * 242;

由于视频项目是完全一样的结构,这将是很好,如果这些RecyclerViews可以重新使用该视频的itemViews一旦他们已经与屏幕刷卡关闭的,应当采取更好的性能提升。

Given that video items are completely same structure, it would be nice if those RecyclerViews can re-use that video's itemViews once they already swipe off with the screen, it shall takes much better performance improvement.

然后我想有一个特殊的RecycledViewPool来传播到每一个嵌套RecyclerViews。

Then i tried to have a particular RecycledViewPool to propagating to every nested RecyclerViews.

public class MainActivity extends Activity {
    private RecyclerView.RecycledViewPool mViewPool;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // create the RecycledViewPool from first and re-use for each nested RecyclerViews.
        mViewPool = new RecyclerView.RecycledViewPool();
        ...
    }
}

即使我做了这方面的努力,我一直注意,正在执行的onCreateViewHolder方法和充气柜获得增长的时候,我刷卡根RecyclerView循环。

Even i done this effort, i keep notice that the onCreateViewHolder method being performed and the inflate counter getting increase during i swipe the root RecyclerView circularly.

private static class VideoAdapter extends RecyclerView.Adapter<GridViewHolder> {
    private List<Video> mVideoList;

    private VideoAdapter(List<Video> videoList) {
        mVideoList = videoList;
    }

    // this method would always invoke during i swipe the RecyclerView.
    @Override
    public GridViewHolder onCreateViewHolder(ViewGroup container, int viewType) {
        Log.e("", String.format("createViewCount : %d", ++MainActivity.STAT_GAME_VIDEO_ITEM_COUNT));
        return new GridViewHolder(inflate(container, R.layout.game_video_item)) {};
    }
}

这是我的想法会工作吗?或者我已经做错了?我想达到这样的效果,任何其他建议,即使是不看好RecyclerView将AP preciative,在此先感谢。

Is this idea of mine will work? or i've doing it wrong? I want to achieve this effect, any other advices even if that aren't about RecyclerView would be appreciative, thanks in advance.

推荐答案

到现在为止,我用网格布局,而不是嵌套RecyclerView和回收的观点这里面的网格布局自己。但它可能不是一个好办法,因为我回收的逻辑很简单。该应用程序仍有点结巴,而快速滚动,我还没有弄明白。作为一个可行的结局,我把我的code在 github上。请通知我,如果你有想法,谢谢。

By now, I used GridLayout instead of the nested RecyclerView, and recycling views which inside those GridLayout myself. But it is probably not a good way because my recycling logical was very simplicity. The application still a little bit stutter while fast scrolling, I haven't figure it out. As a viable ending, I push my code in github. Please advising me if you have ideas, thanks.

这篇关于有没有一种方法来共享多个嵌套RecyclerViews之间的相同的布局管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆