I want to add two child views to a horizontal scroll view. The two views are a ImageView
and a TextView
and the TextView
should be below the `ImageView, both the view should scroll horizontally Is it possible to achieve this? How can it be added? I am new to android.
Thanks in advance.
in my fragment:
LinearLayout lv = (LinearLayout) v.findViewById(R.id.textl);
for (int i=0;i<5;i++){
ImageView iv = new ImageView(getContext());
TextView tv = new TextView(getContext());
tv.setText(text[i]); //defined text and images
iv.setImageResource(images[i]);
lv.addView(iv);
lv.addView(tv);
xml:
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:id="@+id/hs">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/bottle"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/textl"/>
</LinearLayout>
</HorizontalScrollView>