gpt4 book ai didi

java - 如何将RecyclerView添加到LinearLayout(高度问题)

转载 作者:太空宇宙 更新时间:2023-11-04 12:50:39 24 4
gpt4 key购买 nike

我想添加一个带有自定义适配器的recyclerview,但是当我将其添加到LinearLayout时,它不显示任何项目,但是当我将高度设置为500(例如)时,我可以看到这些项目,但它不适用于WRAP_CONTENT或MATCH_PARENT,那么我应该做什么?如何自动设置高度?对不起我的英语

代码:

    adapterCustom = new AdapterCustom(customArrayList);
LinearLayout recyclerLayout = (LinearLayout) LayoutInflater.from(currentActivity).inflate(R.layout.recycler_layout, null);
RecyclerView recycler = (RecyclerView) recyclerLayout.findViewById(R.id.mainRecycler);
LinearLayoutManager layoutManager = new LinearLayoutManager(currentActivity, LinearLayoutManager.HORIZONTAL, false);
recycler.setLayoutManager(layoutManager);
recycler.setAdapter(adapterCustom);
recycler.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
recyclerLyt.addView(recyclerLayout);

我忘了说,我的回收 View 是水平的

最佳答案

请更新 gradle 文件中的库版本:

编译“com.android.support:recyclerview-v7:23.2.0”在此之前,recyclerviews 需要将高度设置为 match_parent 的固定高度。

关于java - 如何将RecyclerView添加到LinearLayout(高度问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35869550/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com