Include same layout multiple times

前端 未结 4 1139
抹茶落季
抹茶落季 2021-02-13 21:56

I have a common layout (common.xml) which I want to include many times in another layout (layout_a.xml). But it only shows me just one time. Why?

common.xml

4条回答
  •  名媛妹妹
    2021-02-13 22:36

    That's what I had done in my Project with Inflater. test1is just a Layout made with a LinearLayout(Vertical) with text and a button and mainofferslayout in that case, the main layout with an image.

    // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_offers_display, container, false);
    
        View inflatedLayout = inflater.inflate(R.layout.test1, (ViewGroup) view, false);
        LinearLayout ll = (LinearLayout) view.findViewById(R.id.mainofferslayout);
    
        ll.addView(inflater.inflate(R.layout.test1, (ViewGroup) view, false));
        ll.addView(inflater.inflate(R.layout.test1, (ViewGroup) view, false));
        ll.addView(inflater.inflate(R.layout.test1, (ViewGroup) view, false));
    

提交回复
热议问题