There are two ways to do this:
Path to the left (using xml, if the number of elements is fixed):
<HorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:id="@+id/ll" android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="horizontal"> <include android:id="@+id/item1" layout="@layout/items.xml"/> <include android:id="@+id/item2" layout="@layout/items.xml"/> <include android:id="@+id/item3" layout="@layout/items.xml"/> </LinearLayout> </HorizontalScrollView>
Path to the right (in action using the Inflator layout, if the number of elements is dynamic):
setContentView(R.layout.main); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout ll = (LinearLayout) findViewById(R.id.ll); View v = inflater.inflate(R.layout.items, ll); for (short i=0;i<3;i++) ll.addView(v);
source share