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
As btse said, the ids in the XML must be unique. It can be achieved in this way:
<include android:id="@+id/common1"
layout="@layout/common" />
<include android:id="@+id/common2"
layout="@layout/common" />
For information about how to access the elements inside those two included views, you can check out this blog post.
The ids when defined in XML must be unique. You are including two layouts that have views that contain the same id.
Here is how you would go about fixing it.
p.s. Unless there is more code that you are not including in your first layout file, that merge tag is useless.
I fixed by setting the layout_height of the RelativeLayout to 250dp since they are overlapped.
That's what I had done in my Project with Inflater
.
test1
is 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));