我想添加一個帶有自定義適配器的回收站,但是當我將它添加到LinearLayout時,它不顯示任何項目,但是當我將高度設置爲500時(例如)我可以看到這些項目,但它不適用於WRAP_CONTENT或MATCH_PARENT,所以我該怎麼辦?我怎樣才能自動設置高度? 對不起我的英語如何將RecyclerView添加到LinearLayout(高度問題)
代碼:
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);
我忘記說了,我的recyclerview是水平
代碼在哪裏? – Stallion
linearLayout的高度是多少? LinearLayout是否在其他一些佈局中? – jdabrowski