我想添加一个带有自定义适配器的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 的固定高度。
我是一名优秀的程序员,十分优秀!