私のxmlレイアウトには、次のような子を配置するカスタムビューがあります。
<com.proj.layouts.components.ScrollLayout
android:id="@+id/slBody"
android:layout_width="700dp"
android:layout_height="400dp">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="child1"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="child2"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="child3"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="child4"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="child5"/>
</com.proj.layouts.components.ScrollLayout>
もう少し説明させてください。子供向けに、既にコンテナが定義されているカスタムScrollViewを作成しました。だから私はそれらをそこに置きたいだけです。
public class ScrollLayout extends LinearLayout {
// View responsible for the scrolling
private FrameLayout svContainer;
// View holding all of the children
private LinearLayout llContainer;
public ScrollLayout(Context context) {
super(context);
init();
}
public ScrollLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
super.removeAllViews(); // kill old containers
svContainer = new HorizontalScroll(getContext());
llContainer = new LinearLayout(getContext());
llContainer.setOrientation(orientation);
svContainer.addView(llContainer);
svContainer.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
llContainer.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
addView(svContainer);
}
... I left out the part which takes care of the scroll event ...
}
llContainerにChild*を追加する方法は何ですか?