java—将列表视图添加到linearlayout,但只显示第一次添加的视图

xwmevbvl  于 2021-06-27  发布在  Java
关注(0)|答案(0)|浏览(168)

我正在尝试向linearlayout添加两个listview,但只显示第一个listview,有人知道为什么吗?

private void populateListView(ConstraintLayout root, List<Product> products){
    ....

    ConstraintLayout.LayoutParams newParams = new ConstraintLayout.LayoutParams(
            ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT);

    ...
    ListView listView = (ListView)getLayoutInflater().inflate(R.layout.list_view_product, null);
    listView.setId(View.generateViewId());
    listView.setLayoutParams(newParams);
    ...

    ListView listView2 = (ListView)getLayoutInflater().inflate(R.layout.list_view_product, null);
    listView2.setId(View.generateViewId());
    listView2.setLayoutParams(newParams);
    ...

    LinearLayout linearLayoutView = (LinearLayout)root.findViewById(R.id.fragment_ll_home);

    linearLayoutView.addView(listView2,0);
    linearLayoutView.addView(listView,1);

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题