Ich habe ein relatives Layout und Hinzufügen von Bildansicht programmatisch in meiner horizontalen scrollview, die in xml.when ich versucht, meine Bildansicht in horizontalScrollView ..im bekommen die Laufzeitausnahme .HorizontalScrollView kann Host nur eine einzige child.could Jungs ihr mir helfenHorizontalScrollView kann nur ein direktes Kind hosten
RelativeLayout.LayoutParams HParams = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
HParams.topMargin = 200 * displayHeight/480;
HsrollView.setLayoutParams(HParams);
for (int i = 0; i < 4; i++) {
ImageView btnTag = new ImageView(this);
btnTag.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
btnTag.setImageResource(R.drawable.book);
btnTag.setTag(i);
btnTag.setId(i);
HsrollView.addView(btnTag);
}
XML-Datei aus
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/directbg"
tools:context=".DirectorActivity" >
<HorizontalScrollView
android:id="@+id/Hscrollview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>