我想添加兩個子視圖到水平滾動視圖。這兩個視圖是ImageView
和TextView
和TextView
應該低於`ImageView,這兩個視圖都應該水平滾動是否可以實現此目的?如何添加?我是android新手。horizontalscrollview與圖像和文字可以添加兩個視圖
在此先感謝。
在我的片段:
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>
好,我會盡力感謝您迴應 – sun
當我添加圖片和文字我有錯誤有指定的孩子已經有一位家長。您必須先調用子對象的父對象的removeView()。 – sun
請你分享一下你的java文件。 –