0
我试图创建一个自定义视图,以取代一个xml /膨胀有一定布局,包含多个预定义的LinearLayout和添加这些看法到每一个预定义的布局。添加在RelativeLayout的意见,不同的布局,膨胀
我的预定义布局包含内部的RelativeLayout作为亲和充气此xml类4个linearlayouts那里延伸的RelativeLayout并如下初始化视图。
private void initView(Context context) {
//Inflate and attach your child XML
View.inflate(context, R.layout.layout_empty_views, this);
llTop = (LinearLayout) findViewById(R.id.linearLayout);
llLeft = (LinearLayout) findViewById(R.id.linearLayout2);
llBottom = (LinearLayout) findViewById(R.id.linearLayout3);
llRight = (LinearLayout) findViewById(R.id.linearLayout4);
}
现在,我接受12个子视图,需要添加3个孩子到每个linearlayout是我现在卡在哪里。在addView函数中由于索引而不能分割视图总是-1。
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
if (llTop == null) {
super.addView(child, index, params);
} else {
//Forward these calls to the content view
llTop.addView(child, index, params);
}
}
在onLayout函数中,由于膨胀我的预定义布局,getChildCount被提高超过12。
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
//super.onLayout(changed, l, t, r, b);
// TODO Auto-generated method stub
Log.v("Count::", String.valueOf(getChildCount()));
/*for (int i = 0; i < getChildCount(); i++) {
View v = getChildAt(i);
removeViewAt(i);
//llTop.addView(v);
if (i < 3) {
llTop.addView(v);
} else if (i > 2 && i < 6) {
llRight.addView(v);
} else if (i > 5 && i < 9) {
llBottom.addView(v);
} else if (i > 9) {
llLeft.addView(v);
}
}*/
}
是的,但我怎么动这个观点到另一个布局 – chiru